Not logged in - Login

Expire a web page

An example of how to expire a web page immediately.

// get the response object
System.Web.HttpResponse resp = System.Web.HttpContext.Current.Response;

if (resp != null)
{
   // date in the past
   resp.AddHeader("Expires", "Sat, 01 Jan 2000 01:00:00 GMT");

   //always modified
   resp.AddHeader("Last-Modified", 
      DateTime.Now.ToUniversalTime().ToLongTimeString() + " GMT");

   // HTTP/1.1 
   resp.AddHeader("Cache-Control", "no-cache, must-revalidate");

   //HTTP/1.0 
   resp.AddHeader("Pragma", "no-cache");

   //last ditch attempt!
   resp.Expires = -1;

   // set the cache-control header to not cache the page.
   resp.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
}