【发布时间】:2018-01-29 18:54:26
【问题描述】:
我已经尝试了所有可能的方法,但我仍然无法注销当前用户。 目前我有以下代码:
_authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
string sKey = (string)HttpContext.Current.Session["user"];
string sUser = Convert.ToString(HttpContext.Current.Cache[sKey]);
HttpContext.Current.Cache.Remove(sUser);
HttpContext.Current.Session.Clear();
HttpContext.Current.Response.Cookies.Clear();
HttpContext.Current.Request.Cookies.Clear();
HttpContext.Current.Session.Abandon();
在此之后,会话仍未清除。 有什么想法吗?
认证启动:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
登录代码:
public override ApplicationUser Handle([NotNull]LoginCommand command)
{
var user = _userManager.Find(command.Login, command.Password);
if (user == null)
{
throw new RentalApplicationValidationException("No valid login");
}
_authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
var identity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
_authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);
return user;
}
【问题讨论】:
-
您的登录代码是什么样的?和Authentication启动配置?
-
感谢您的回复。请参阅我的帖子中的编辑。
-
实际的
SignOut看起来不错,但您正在谈论会话。 Identity 不使用会话进行身份验证,仅使用 cookie。您还有其他使用会话进行身份验证的代码吗? -
不,我没有在其他任何地方使用它。值得注意的是,当我直接在控制器中触发注销方法时,一切正常。从我的命令触发注销方法时,它不起作用。
标签: c# asp.net-identity