Avatar of Cjames
Flag for United States of America asked on

prevent page caching

We've got a website which is having intermittent caching problems -- as soon as the user clears their cache the problems are not recreatable for some unforceable time for that user.  The website is hosted at GoDaddy, so I can't change IIS settings.  This caching problem is threatening the entire business model.

I should mention this appears to be affecting IE8 only, it has not been known to happen on IE7, Safari, Chrome, or Firefox.

I have put Response.Cache.SetCacheability(HttpCacheability.NoCache); in the page load, I have put <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Expires" CONTENT="-1">  in the header.

I just found the following, do I need to put this on every page, will it fix the problem, or do we need to find a host that will turn off caching and does anybody have any idea what host does that?

        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

ASP.NETWeb ServersC#

Avatar of undefined
Last Comment

8/22/2022 - Mon
Nitesh Luharuka

you can set these in global.asax/web.config  file
Amandeep Singh Bhullar

Add the following line on top of the Page_Load event handler and your ASP.NET page will not be cached in the users browsers:


You can configure the application's cache API in your Web.config file. As with the page output cache, application hosters can set configuration properties in the Machine.config file and lock cache configuration settings for all applications. The application cache API is configured in the CacheSection. For example, you can disable item expiration with the following configuration element:

<cache disableExpiration="true" />

You can also specify other application cache API configuration settings by assigning values to attributes such as DisableExpiration and DisableMemoryCollection within the configuration file's CacheSection.
Source Article: http://msdn.microsoft.com/en-us/library/ms178606.aspx


private void Page_Load(object sender, System.EventArgs e)







This worked for me

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";

you can try this

<%OutputCache Location="None"%>

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Hi There,
caching is handled differently by different browsers.
I had this same issue when I was working on Bank's application.

The headers you are passing will work on all the browsers.
do you use master file or have a header file which is included in all files?
you can call this function from there.


pradyahuja -- By all the headers, you mean the ones beginning with Response.ClearHeaders?

Thanks! Knowing that would be a big help.

No master page or header file -- I couldn't get the desired functionality -- maybe when things calm down I can refactor.  

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

I am bit disagree with the selection of answer. I have already provided all same options in my comment # 26598443. there is a link provided which have everything you wanted.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.

hi Vora,
your solution will not work on chrome

this links http://www.codekeep.net/snippets/82f96fd3-9374-4b1b-8c3a-e83ca2d49682.aspx which i had already posted , provide the same result which you had provided

So this means your solution will also not work in chrome.

Sorry vora. You did not confirm my "new code" would solve the problem AND you told me to do something I indicated I was already doing that didn't fix the problem, which indicated to me you hadn't read the question.  
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

@pradyahuja I was thinking that you had copied a code from that link which i had provided as both are totally Identical. I had provided link on 17 feb and you have answered on 18th Feb.


mate, I dint provide any code at all...

look carefully..
I explained the code...
and confirmed that the code in question will work.
as I have done same thing in our staging servers.

cool it guys.... shouldn't be this much hot discussion in summer!!!! (at least here at my place).


>>rm my "new code" would solve the problem <<

what do you mean by this? as I don't see any new code in any of the post after question.

>>I explained the code...<<

yes, true, there is small explanation.


don't be so rude. may not be copied from the link you have provided but I agree that the link you provided and the answer selected both are identical and there is a big difference in time too.


anyway, as per me there should be at least split.

Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.

I copied the code from question itself....
Ritesh, what r u talking about...
Summer... seems like we from same country :)
or at least are neighbors

Yes Predy Ahuja. I am from Gujarat - India. not much active in .NET zone, just used to come sometimes and seen good discussion so jump in it!!!!

The new code is in the initial post where I indicated "I found this" starting with response.clearheaders.   Which I will point out is pretty much the same as the code both provided. What I really needed was confirmation that it would solve the problem.

Explanation of points awarded:

Since I had already posted that same code in the initial post my award of points was Not based on the link or the code in the answer selected. Points were awarded based on confirming that code would resolve the problem.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

oh.. u from Gujarat...
I thought it's still winters in India...
I am from Oz..
winters are approaching here :)

I certainly didn't mean to hurt anybody's feelings!  It is simply one response provided what I needed and that's the one I accepted.