Wednesday, 28 November 2012

Deny or avoid user on browser back button after Logout

Problem:

A very common problem that we face in web application is that when user logged out, and again click the browser back button, it shows the last accessed page by the user when user was logged in, even we have included any check whether the user is signed inn or not, it is because browser shows the cached webpage.

Solution:

After some net surfing , I was able to solve my issue by including these code of snippets in my code :

  Response.Cache.SetCacheability(HttpCacheability.NoCache);
  Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
  Response.Cache.SetNoStore();
  Response.AppendHeader("Pragma", "no-cache");

Hope this helps.