Wednesday, October 27, 2010

(ASP.NET) Prevent pages from being displayed if user clicks back button on his browser

When using asp.net applications, you might face a problem of clicking the back button of his browser (internet explorer) after he logged out.
It is expected that the user could not be able to do that ,buy you might face that he can do it.
The problem could easily be solved by using the code below:
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

The code above sets the expiration date of the page to a date that has been based and informing the browser not to cache or store this page .
Hope it helps all of you ...