即使在 Logout() 之后,IsAuthenticated 始终为真

IsAuthenticated is always true even after Logout()

我正在尝试在我的 MVC 应用程序中实现表单授权,并且在大多数情况下它都在工作 fine.However,当我触发我的 Logout() 方法时,没有任何反应。我有

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 的建议,但问题仍然存在。

好的,我发现错误了。

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