【问题标题】:ASP.NET Identity - AuthenticationManager.SignOut not workingASP.NET 身份 - AuthenticationManager.SignOut 不起作用
【发布时间】:2015-09-03 22:35:41
【问题描述】:

我正在尝试在 JWT 令牌过期时注销我的用户。但由于某种原因,在我退出后 ClaimsPrincipal 仍然存在。

例如:Request.IsAuthenticated 始终为真,即使在我唱出来之后也是如此。

我正在退出所有可用的身份验证类型。 (ApplicationCookie、ExternalCookie、Auth0)。

我不确定我可能在这里遗漏了什么。

 internal static void SignOut()
    {
        var authenticationManager = HttpContext.Current.Request.GetOwinContext().Authentication;
        if (authenticationManager == null) return;
        var appTypes = authenticationManager.GetAuthenticationTypes().Select(at => at.AuthenticationType).ToArray();
        authenticationManager.SignOut(appTypes);

        var httpResponse = HttpContext.Current.Response;
        var httpRequest = HttpContext.Current.Request;
        httpResponse.Redirect(
            string.Format("https://{0}/logout?returnTo={1}",
                ConfigurationManager.AppSettings["auth0Domain"],
                 httpRequest.Url));
    }

感谢任何可能指导我解决此问题的建议/想法。

【问题讨论】:

  • 不确定您使用的是哪个身份服务器,但这里有来自 Identityserver identityserver.github.io/Documentation/docs/overview/… 的指南。请参阅“添加注销”
  • Startup.Auth.cs中显示代码?
  • @trailmax 感谢您的宝贵时间。我正在从“ActionFilter”调用 Signout(),即使在调用 Signout 之后,操作方法也会继续执行。我通过注销会话解决了这个问题,然后在过滤器中设置了 'filterContext.Result = new RedirectResult('logouturl)'。这样它就停止了 Action 方法的执行并正确地注销了用户。

标签: asp.net asp.net-identity claims-based-identity claims


【解决方案1】:

感谢您的宝贵时间。我正在从“ActionFilter”调用 Signout(),即使在调用 Signout 之后,操作方法也会继续执行。我通过退出会话解决了这个问题,然后设置

filterContext.Result = new RedirectResult('logouturl)

在过滤器中。这样它就停止了 Action 方法的执行并正确地注销了用户

【讨论】:

    猜你喜欢
    • 2023-04-11
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    相关资源
    最近更新 更多