Disable Caching on an ASP.Net Page
I have been working on database driven ASP.Net site lately and have been having problems with the browser caching pages variables. This is causing issues when the user uses the back command to navigate to the previous page instead of using the provided command button to return to the page they need.
In order to prevent the page from being cached and force it to be loaded as a new page each time, add the following code to the Page_Load event :
VB.Net:
Response.Buffer = True Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0, 0)) Response.Expires = 0 Response.CacheControl = "no-cache"
C#:
Response.Buffer = true; Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)); Response.Expires = 0; Response.CacheControl = "no-cache";
So simple, yet so effective.
If you found this page useful, consider linking to it.
Simply copy and paste the code below into your web site (Ctrl+C to copy)
It will look like this: Disable Caching on an ASP.Net Page
Enjoy this post? Please consider leaving a comment or subscribe to the feed and get future articles delivered to your feed reader.




Thanks a ton!
This one has solved my problem. didnt helped me.