Sponsored Links

Disable caching of individual ASP.NET pages

Sometimes it is useful to force a browser to get the latest version of a page from the server.  For example after a user logs out or where the data displayed is from a database that may have been updated.  Whilst you can configure global caching options for IIS or within your c# or VB.NET application, it's easy to disable the caching of just a single page. 
Add the following code the code behind or within <% %> tags.  You should be able to use this in classic ASP as well.

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

An alternative is this:

Response.Expires = 0
Response.Expiresabsolute = Now() - 1442
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"

Back To Servers

Options