How can I urn off browser caching for all aspx pages?

  • Thread starter Thread starter Ken Varn
  • Start date Start date
K

Ken Varn

Is there anyway within my web application that I can have all browser
caching turned off for all aspx pages sent by my IIS server? I need to have
all caching off in order for certain things to work properly, and I can't
always rely on the user disabling their cache settings at the browser level.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
Unfortunately, using :
<META HTTP-EQUIV="pragma" Content="nocache">
doesn't work too good in some browsers.

The correct object to use is :

SetCacheability(HttpCacheability.NoCache)




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
The correct object to use is :

SetCacheability(HttpCacheability.NoCache)

Agreed.

Perhaps even accompanied by:
SetAllowResponseInBrowserHistory(false)

Jeppe Jespersen
Denmark
 
note: these are all hints to the browser (and proxy servers) and may be
ignored.

-- bruce (sqlwork.com)
 
Hmm...

SetAllowResponseInBrowserHistory(false) is the default.

You only need to set
HttpCachePolicy.SetAllowResponseInBrowserHistory
when you need to set it to true ( to override the NoCache setting ).




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Thanks for all of the information on this post. I take it that there is no
global way to turn caching off for the entire ASP.NET application? It would
be nice if there was something in web.config where I could turn off caching
for the whole application.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
 
I really hesitated before writing this, since tinkering
with basic functionality could have unexpected results.

You could try disabling the entire OutputCache module.

The OutputCache is a module which is added to ASP.NET's
core via a line in machine.config's httpmodules section :


<httpModules>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />

You could *experiment* removing that line.
You might have to make other adjustments, too.

Disclaimer: if you do this, you do it on your own behalf.
I do not accept any responsibility for unexpected results.

Good luck, if you decide to experiment with this.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Ken Varn said:
Thanks for all of the information on this post. I take it that there is no
global way to turn caching off for the entire ASP.NET application? It would
be nice if there was something in web.config where I could turn off caching
for the whole application.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
I tried another approach that seems to work, but please verify.

I modified the global.asax.cs file an added the
SetCacheability(HttpCacheability.NoCache) call in the
Application_BeginRequest event.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Juan T. Llibre said:
I really hesitated before writing this, since tinkering
with basic functionality could have unexpected results.

You could try disabling the entire OutputCache module.

The OutputCache is a module which is added to ASP.NET's
core via a line in machine.config's httpmodules section :


<httpModules>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />

You could *experiment* removing that line.
You might have to make other adjustments, too.

Disclaimer: if you do this, you do it on your own behalf.
I do not accept any responsibility for unexpected results.

Good luck, if you decide to experiment with this.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Ken Varn" <nospam> wrote in message news:[email protected]...
 
Great idea!

That will, in effect, act as a global directive since the
Application_BeginRequest event is called in all requests.

Congratulations on your smart move!



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Bruce said:
note: these are all hints to the browser (and proxy servers) and may
be ignored.

True for browsers (unfortunately), but proxies? The HTTP 1.1 spec has
MUST NOT written all over sections 14.9.1 and 14.9.2 ;-)


Cheers,
 
Back
Top