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、不需要AI权限,帮助...
分享个大家!wepoker数据... 分享个大家!wepoker数据分析工具,pokerrrr2辅助,其实是有挂(真的有挂)1、辅助软件下...
三分钟了解!aapoker怎么... 三分钟了解!aapoker怎么控制牌,哈糖大菠萝开挂,原来有挂(竟然有挂)1、进入到是否有挂之后,能...
专业讨论!德州局hhpoker... 专业讨论!德州局hhpoker,wepoker辅助透视,竟然存在有挂(有挂教程)专业讨论!德州局hh...
科技揭秘!wepoker辅助透... 科技揭秘!wepoker辅助透视软件,菠萝德普辅助器免费版在哪里,本来真的是有挂(有挂教程)科技揭秘...
必备科技!德普之星透视软件免费... 必备科技!德普之星透视软件免费入口官网,wepoker网页版透视方法,其实是真的有挂(有挂方式)1、...
盘点十款!pokemmo辅助器... 盘点十款!pokemmo辅助器,德州透视是真的假的,都是真的有挂(真实有挂)1、起透看视 辅助软件价...
热点讨论!wpk刷入池率脚本,... 热点讨论!wpk刷入池率脚本,约局吧辅助器,一直是有挂(有挂功能)1、超多福利:超高返利,海量正版游...
最新研发!hhpoker有没有... 最新研发!hhpoker有没有作弊辅助,wepoker有没有插件,确实有挂(有挂秘诀)1)有没有挂:...
我来教大家!wejoker私人... 我来教大家!wejoker私人辅助软件,aapoker插件,其实是真的有挂(有挂解密)1、公共底牌简...