Avatar of Cjames
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.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

Thanks
ASP.NETWeb ServersC#

Avatar of undefined
Last Comment
Cjames

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:

Response.Cache.SetCacheability(HttpCacheability.NoCache)


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
vora_bhaumik

http://www.codekeep.net/snippets/82f96fd3-9374-4b1b-8c3a-e83ca2d49682.aspx

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

{

if(!Page.IsPostBack)

{

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Cache.SetAllowResponseInBrowserHistory(false);

}

}
This worked for me

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

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
pradyahuja

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.


Cjames

ASKER
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.  
ASKER CERTIFIED SOLUTION
pradyahuja

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
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
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vora_bhaumik

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
pradyahuja

hi Vora,
your solution will not work on chrome
vora_bhaumik

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.
Cjames

ASKER
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
vora_bhaumik

@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.

--Bhaumik
pradyahuja

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.
RiteshShah

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

@Cjames,

>>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.

@pradyahuja,
>>I explained the code...<<

yes, true, there is small explanation.

@vora_bhaumik,

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.

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

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
RiteshShah

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!!!!
Cjames

ASKER
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
pradyahuja

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

ASKER
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.