0
我想在我的MVC应用程序中实现表单授权,并且大部分它工作正常。但是,当我触发我的Logout()方法时,什么都不会发生。我有IsAuthenticated即使在注销后也是如此()
System.Web.HttpContext.Current.User.Identity.IsAuthenticated
在我的主页,所以我可以看到,它仍然是登录之后。 以下是我的注销方法。
public ActionResult Logout(){
TempData.Clear();
FormsAuthentication.SignOut();
Session.Abandon();
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
HttpContext.User =new GenericPrincipal(new GenericIdentity(string.Empty), null);
return RedirectToAction("Index", "Home");
}
---编辑---
我已经加入了HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
如建议通过DGibbs,但问题仍然存在。
对不起,有人说有什么不对的格式,现在加入。 –
您使用的是什么版本的MVC?我设法使用'FormsAuthentication.SignOut();'复制你的问题,但是使用:AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);'为我做了诀窍。 – DGibbs
我的AuthenticationManager根本没有任何功能? :/ –