Asp.netcore5IdentitySignOutAsync不起作用
创始人
2024-09-17 11:30:26
0

问题可能是由于在配置身份验证服务时未正确设置Cookie属性而导致。以下是正确设置Cookie属性的示例代码:

services.ConfigureApplicationCookie(options =>
{
    options.Cookie.HttpOnly = true;
    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
    options.SlidingExpiration = true;
});

如果仍然遇到问题,则可以尝试使用以下代码实现SignOutAsync:

await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync("Identity.Application");

这将同时注销Cookie和Identity认证令牌。

另外,检查是否在登录时将RememberMe设置为true。如果是,则需要调用HttpContext.SignOutAsync()。否则,将不会注销用户。

if (signInResult.Succeeded)
{
    // Make sure the user's credentials exist on the cache.
    HttpContext.Session.SetString("Username", model.Username);
    HttpContext.Session.SetString("Password", model.Password);

    if (model.RememberMe)
    {
        // When the user checks out the remember me option. The cookie will be valid for 7 days.
        var authProperties = new AuthenticationProperties
        {
            IsPersistent = true,
            ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7)
        };
        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, authProperties);
    }
    else
    {
        // When the user does not check the remember me option. The cookie will be valid for the current session.
        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal);
    }
    return LocalRedirect(returnUrl);
}

希望这能帮助到你解决Asp.net core 5 Identity SignOutAsync不起作用的问题。

相关内容

热门资讯

据相关数据显示!边锋老友修改器... 据相关数据显示!边锋老友修改器,切实是真的辅助平台(有挂细节)-哔哩哔哩1、操作简单,无需边锋老友修...
长期以来!悠闲卡五星辅助器,真... 长期以来!悠闲卡五星辅助器,真是存在有辅助插件(真实有挂)-哔哩哔哩1)悠闲卡五星辅助器有没有挂:进...
更值得关注的是!围棋辅助器乐乐... 更值得关注的是!围棋辅助器乐乐,果然是有辅助器(真的有挂)-哔哩哔哩1、完成围棋辅助器乐乐辅助器v3...
迎来新发展!情怀游戏字牌辅助,... 迎来新发展!情怀游戏字牌辅助,都是有挂辅助插件(有挂详细)-哔哩哔哩1、情怀游戏字牌辅助透视辅助软件...
现场直击!哥哥打大a有没有辅助... 现场直击!哥哥打大a有没有辅助,确实有挂辅助软件(有挂猫腻)-哔哩哔哩1、让任何用户在无需哥哥打大a...
最终!好友赣南新版本辅助,都是... 最终!好友赣南新版本辅助,都是有挂辅助插件(新版有挂)-哔哩哔哩1、好友赣南新版本辅助免费脚本咨询教...
据报道!奇迹陕西游戏辅助器,确... 您好,奇迹陕西游戏辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
做出回应!雀姬辅助器,一贯真的... 做出回应!雀姬辅助器,一贯真的是有辅助工具(有挂实锤)-哔哩哔哩1、让任何用户在无需雀姬辅助器安装教...
最终!潮友会鱼虾蟹塞子概率计算... 最终!潮友会鱼虾蟹塞子概率计算方式,好像真的是有辅助脚本(有挂透视)-哔哩哔哩潮友会鱼虾蟹塞子概率计...
事发当天!德州扑克游戏辅助器,... 事发当天!德州扑克游戏辅助器,总是存在有辅助软件(有挂猫腻)-哔哩哔哩1、很好的工具软件,可以解锁游...