Return to Snippet

Revision: 13731
at May 4, 2009 10:28 by jink


Initial Code
//prevent browsers from caching the page.
Response.Cache.SetCacheability(HttpCacheability.NoCache);

#region Google cache fix (prevents google from cachine the page too long)
System.IO.FileInfo currentInfo = new System.IO.FileInfo(Request.PhysicalApplicationPath);
System.IO.FileInfo currentDirInfo = new System.IO.FileInfo(Request.PhysicalPath);

DateTime modifiedTimeToUse;
if (currentInfo.LastWriteTime > currentDirInfo.LastWriteTime)
	modifiedTimeToUse = currentInfo.LastWriteTime;
else
	modifiedTimeToUse = currentDirInfo.LastWriteTime;

Response.AppendHeader("Last-Modified", modifiedTimeToUse.ToString("ddd, dd MMM yyyy hh:mm:ss GMT"));
#endregion

Initial URL


Initial Description
Code snippet prevents caching of the page by setting http header values and a LAST MODIFIED header to prevent google from caching too long.  This should go into the page load event.

Initial Title
ASP.net: Prevent Caching of a Page

Initial Tags
aspnet, cache

Initial Language
ASP