Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: Logging out in the view once called

Tags:

asp.net-mvc

I have a logout action which directs to a logout view. The user information is still displayed after clicking the logout button. I fully logout after I go to a different url, why is this? How do I handle this? Client-side redirect?

Action:

    public ViewResult LogOut()
    {
        FormsAuthentication.SignOut();
        return View();
    }
like image 796
Shawn Mclean Avatar asked Dec 05 '25 15:12

Shawn Mclean


2 Answers

Try getting rid of the authentication token:

FormsAuthentication.SignOut();
Context.Response.Cookies.Item(FormsAuthentication.FormsCookieName).Expires = Date.Now;
return RedirectToAction("LogOut");

Also, make sure the page is not cached:

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore();
like image 92
jsteve81 Avatar answered Dec 08 '25 15:12

jsteve81


Try Session.Abandon(); after the logout

like image 32
Russell Steen Avatar answered Dec 08 '25 15:12

Russell Steen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!