How to prevent client cache and getting a server request even when back button is clicked

Hi,

Many a times we do not want browser to show data from cache. For example when user hits the back button of the browser, the browser shows the last page from the cache and does not make a post back to the server. (This is why when some one clicks on the back button of the browser the system looks so fast).

But many a times we do not want the browser to show data from the cache. There are requirements where the data is very dynamic and if browser shows the data from the cache then it can give wrong indication to the user.

Controlling the back button of the browser is not such a good idea because we are trying to stop the user at the client end.  But what we can do is ask the browser to not to cache the page in the client end and always make a call to the server before showing the page.

This can be easily done by expiring the response. Here is the code for the same.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);

This will make the browser make a request to the server even when the back button of the browser is clicked.

Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia