Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page still shows after logout when back button is clicked asp.net mvc 3

I have seen lot of questions almost similar to this. But, I haven't found an answer that will fix my problem.

I have a logout button and I used Session.Abandon() and Session.Clear() to clear the session. It works fine. But, whenever I hit the back button on browser the page is still showing. But, it's supposed to show the login form because the user already logged out.

Controller:

[HttpPost]
public ActionResult LogOut()
{
     Session.Clear();
     Session.Abandon();
     return RedirectToAction("Index", "LogIn");
}

How to fix this?.Any suggestion is highly appreciated. Thanks in advance.

like image 208
user3462803 Avatar asked Nov 23 '25 19:11

user3462803


1 Answers

You can set NoCache in global.asax

protected void Application_BeginRequest()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
    Response.Cache.SetNoStore();
}
like image 54
Ashwini Verma Avatar answered Nov 26 '25 11:11

Ashwini Verma