Skip to content

Instantly share code, notes, and snippets.

@cemerson
Created October 17, 2012 17:39
Show Gist options
  • Save cemerson/3906944 to your computer and use it in GitHub Desktop.
Save cemerson/3906944 to your computer and use it in GitHub Desktop.
C#: Prevent Page Caching
Method 1:
//Response.ClearHeaders();
//Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
//Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
//Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
//Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
//Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
//Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
//Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
//Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
//Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
//Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
Method 2:
//Response.ExpiresAbsolute = DateTime.Parse("1/1/1980");
//Response.AddHeader("cache-control", "no-store, must-revalidate, private");
//Response.AddHeader("Pragma", "no-cache");
Method 3:
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Method 4:
//Response.Buffer = true;
//Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
//Response.Expires = 0;
//Response.CacheControl = "no-cache";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment