简体   繁体   中英

IsAuthenticated is always true even after Logout()

I am trying to implement Form Authorization in my MVC application and for the most part it is working fine.However, when i trigger my Logout() method nothing happens. I have

System.Web.HttpContext.Current.User.Identity.IsAuthenticated

on my homepage so i can see that it is still logged in afterwards. Below is my logout method.

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");
    }

--- Edit ---

I have added the HttpContext.GetOwinContext().Authentication.SignOut(DefaultA‌​uthenticationTypes.A‌​pplicationCookie);

as was recommended by DGibbs, but the problem persists.

Okay, i found the mistake.

If anyone else runs into this problem and they have tried what people said, try checking the properties of the project, apparently i had enabled WindowsAuth there and disabled AnonymousAuth, but once i switched those around its working like a charm.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM