Spotlight IT Ramblings Blog

I'm living in Dublin, Ireland and this is a collection of ramblings about my day-to-day activities in the exciting world of web development ;-) Technologies used and projects under development. Also links of interest, mostly completely work un-related....

Thursday, August 24, 2006

Forcing pages to expire in .Net 2.0

Add the following

<meta http-equiv="Expires" content="0" />

<meta http-equiv="Cache-Control" content="no-cache" />

<meta http-equiv="Pragma" content="no-cache" />

To the HTML in the <title> element of your master pages for your projects, Pragma: no-cache prevents caching only when used over a secure connection. A Pragma: no-cache META tag is treated identically to Expires: -1 if used in a non-secure page. The page may be cached but marked as immediately expired.

As some browsers ignore these META tags so also added HTTP headers to expire in the master page code-behind in the Page_Load event

Response.Cache.SetCacheability(HttpCacheability.NoCache)Response.Cache.SetNoStore()

Response.Cache.SetExpires(DateTime.MinValue)

This is about all you can do to try to force the browser to not cache a page.

The only other place where caching could be set is in the IIS virtual directory properties, in the HTTP headers tab there is an option to "Enable Content Expiration" which can be set to "Expire Immediately". This should effectively add the same headers that the code behind Response.Cache calls was doing.

There is obviously a lot of overlap with all these techniques. You can install the free ieHTTPHeaders toolbar into IE http://www.blunck.info/iehttpheaders.html to ensure all these headers are set correctly.

If you had control over all the client machines we could change Internet Explorer on the "General Tab", "settings" option to "Check for newer versions of stored pages" to "every visit to the page". Which should disregard any cached items client side.

 

 

 

0 Comments:

Post a Comment

<< Home

 

Valid CSS!
news section


news seperator