Home             About Us             Sign Guest Book             Contact Us             Subscribe              RSS  
Articles
Tools
Code Snippets
Links
Tips & Tricks
FAQ
Resources
Articles
Code Snippets
Links
FAQ
Resources

Saravana Kumar
Vinod Kumar

Click on the image to subscribe to our Monthly Newsletter.


Click here for Archives

No Chats Available

Disabling Back button in ASP.NET

     In your application you might come across the situation where you need to disable back button. For example if you consider this scenario, user gets data which can change frequently from database to display it in the screen. From that screen user can go another page where he presses back button of browser to come back to this page again. During that time browser might show the page which is in cache because of which user might not see the approriate data.

     To avoid this you can open the browser without toolbar. So that user wont see the back button. But in lots of cases we cant do this. Other way for doing this is, dont cache the page. So everytime any page is requested it will go to the server. Hence user will get the current data.

      For avoiding page to be cached, you need to set the following properties for response object.

                                Response.Buffer = True 
                                Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0, 0)) 
                                Response.Expires = 0 
                                Response.CacheControl = "no-cache"

       ExpiresAbsolute : Gets or sets the absolute date and time at which to remove cached information from the cache.

       Expires : Gets or sets the number of minutes before a page cached on a browser expires. If the user returns to the same page before it expires, the cached version is displayed.

       CacheControl :   Sets the Cache-Control HTTP header to Public or Private. Possible values:

                             Public - may be cached in public shared caches 
                             Private - may only be cached in private cache
                             no-cache - may not be cached 
                             no-store - may be cached but not archived

Comment about this article
Free Hit Counters
Free Hit Counters