Tuesday, 2 November 2010

Forcing browser to refresh on back button

This is a bit of perennial issue with web apps. When the user hits the back button the page comes out of their cache and it looks like they have just undone what they just did. This is a particular problem with asp.net applications as they are so postback heavy.

It is pretty easy to force the page to refresh from the server in IE but it is not obvious in firefox. Anyway, after much internet trawling I found this in a blog comment somewhere and thought it deserves it's own post. (Many thanks person who figured this out).

// The following combination disables page caching

// for firefox\ie\chrome

Response.Buffer = true;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Cache.SetAllowResponseInBrowserHistory(false);

Response.Cache.SetNoStore();

1 comment:

  1. I had worked in asp.net for some time and during development we are in situation that we need to refresh the page on back button.Thanks for giving code.

    ReplyDelete