Shawn Mclean
Shawn Mclean

Reputation: 57469

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

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

Upvotes: 3

Views: 399

Answers (3)

Shawn Mclean
Shawn Mclean

Reputation: 57469

I use a javascript event to redirect the page.

Upvotes: 0

jsteve81
jsteve81

Reputation: 735

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();

Upvotes: 2

Russell Steen
Russell Steen

Reputation: 6612

Try Session.Abandon(); after the logout

Upvotes: 1

Related Questions