2016-09-16 42 views
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(DefaultA‌​uthenticationTypes.A‌​pplicationCookie);

如建议通过DGibbs,但问题仍然存在。

+0

对不起,有人说有什么不对的格式,现在加入。 –

+0

您使用的是什么版本的MVC?我设法使用'FormsAuthentication.SignOut();'复制你的问题,但是使用:AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);'为我做了诀窍。 – DGibbs

+0

我的AuthenticationManager根本没有任何功能? :/ –

回答

0

好的,我发现了错误。

如果有其他人遇到这个问题,他们已经尝试了人们说的话,试着检查项目的属性,显然我已经启用了WindowsAuth并禁用了AnonymousAuth,但是一旦我切换它的工作就像一个魅力。

enter image description here

相关问题