Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using IE8 to access my application. I have implemented below code to make sure my web pages are not cached.

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);


When I validate/verify the HTTP response using fiddler tool, I do not see any expiration details (max-age or Expires) within my reponse. I see Cache-Control: private. How do I make sure that my pages are not being cached?
Posted
Comments
Zoltán Zörgő 15-Aug-13 9:26am    
You should put this setting at the point after the actual response object is created. There is no "template" you can set up.
What technology are you using: Web Forms, MVC, Web Pages?
Vipul Mehta 15-Aug-13 10:17am    
I have created an httpModule class and have implemented this code there. I am using Web Forms with ASP.Net 3.5.
Vipul Mehta 19-Aug-13 14:38pm    
I have implemented below code within the BeginRequest application event within my custom HttpModule class and registered it within the config file. But still within my response header, I see Cache-Control:private.

I am using IE8 and Fiddler web debug tool to monitor my responses.

public class AddCustomHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

void context_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Response != null)
{
HttpContext.Current.Response.AppendHeader("Cache-Control", "no-store, no-cache, must-revalidate");
HttpContext.Current.Response.AppendHeader("Pragma", "no-cache");
HttpContext.Current.Response.AppendHeader("Expires", "0");
}
}
}

<httpmodules>
<add name="AddCustomHeaderModule" type="Namespace.AddCustomHeaderModule">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900