【发布时间】: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