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(DefaultAuthenticationTypes.ApplicationCookie);
as was recommended by DGibbs, but the problem persists.
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.