Turn off caching

R

Rohit

I need to turn off caching in my ASP.NET page. I have set the following code
in Page Load event:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Still, sometimes the page is retreived from cache. Are there any other
options I need to set?

TIA
Rohit
 
G

Guest

Rohit,

Which cache are you trying to disable? The caching on the server or the
caching on the client? If you are seeing cached data, it could be server-side
or client-side

Have you checked you settings within IE to see if the page is being cached
client-side?

Also, have you enabled Content Expiration within IIS for the Web you are
testing?

Finally, if you are viewing the pages through the ISA server
(firewall/proxy), then be aware that ISA could be caching the pages for you:
both INbound and OUTbound pages.

Respectfully,

Andrew Corley
 
S

Steven Cheng[MSFT]

Hi Rohit,

I think Andrew's suggestions are reasonable since there could be many
things that can cache the page. In spite of the asp.net serverside or IIS
's cache, if what you want to disable is just the client browser's cache,
you can try set the Response.Expire = -1 so as to make the page expire
immediatly at client side.

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Rohit,

Any further ideas or questions on this issue? If there is anything else we
can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Y

Yas

Hello,
I have a similar problem. In my case I have a iFrame that I load with several versions of an html file. The html file that I load has a different content every time but is has the same name. The problem that I have is that it shows always the first document that I loaded in the iFrame.
When I select the option: 'enable content expiration/expire inmediately' in IIS everything works ok but I want to get the same behavior from my code. I have tried several things but nothing works.
I would appreciate very much any help to solve this problem,

Thanks,

Yas
PS. here are some of the things that I have tried (in page_load):

Response.Expires = -1;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-2);
Response.CacheControl = "";
Response.AppendHeader("Pragma", "no-cache");

myframe.Page.Response.Expires = -1;
myframe.Page.Response.ExpiresAbsolute = DateTime.Now.AddDays(-2);
myframe.Page.Response.CacheControl = "";
myframe.Page.Response.AppendHeader("Pragma", "no-cache");


From http://www.developmentnow.com/g/8_2004_11_0_0_4579/Turn-off-caching.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
I

intrader

Hello,
I have a similar problem. In my case I have a iFrame that I load with several versions of an html file. The html file that I load has a different content every time but is has the same name. The problem that I have is that it shows always the first document that I loaded in the iFrame.
When I select the option: 'enable content expiration/expire inmediately' in IIS everything works ok but I want to get the same behavior from my code. I have tried several things but nothing works.
I would appreciate very much any help to solve this problem,

Thanks,

Yas
PS. here are some of the things that I have tried (in page_load):

Response.Expires = -1;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-2);
Response.CacheControl = "";
Response.AppendHeader("Pragma", "no-cache");

myframe.Page.Response.Expires = -1;
myframe.Page.Response.ExpiresAbsolute = DateTime.Now.AddDays(-2);
myframe.Page.Response.CacheControl = "";
myframe.Page.Response.AppendHeader("Pragma", "no-cache");


From http://www.developmentnow.com/g/8_2004_11_0_0_4579/Turn-off-caching.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Try an old trick: add a parameter that changes each time you submit
 
J

Joerg Jooss

Yas said:
Hello,
I have a similar problem. In my case I have a iFrame that I load
with several versions of an html file. The html file that I load has
a different content every time but is has the same name. The problem
that I have is that it shows always the first document that I loaded
in the iFrame. When I select the option: 'enable content
expiration/expire inmediately' in IIS everything works ok but I want
to get the same behavior from my code. I have tried several things
but nothing works. I would appreciate very much any help to
solve this problem,

Thanks,

Yas
PS. here are some of the things that I have tried (in page_load):

Response.Expires = -1;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-2);
Response.CacheControl = "";
Response.AppendHeader("Pragma", "no-cache");

myframe.Page.Response.Expires = -1;
myframe.Page.Response.ExpiresAbsolute = DateTime.Now.AddDays(-2);
myframe.Page.Response.CacheControl = "";
myframe.Page.Response.AppendHeader("Pragma", "no-cache");

Uh uh, this looks like a programmer in panic mode ;-)

Now for the usual answer:

There's no guarantee that a browser applies caching or expiration
instructions to locally stored pages. Still, most browsers behave this
way.

Either set the OutputCache directive on your page(s)

<%@ OutputCache Location="None" %>

or set the Cache property of the HttpResponse in your code-behind class:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Using SetNoStore() as Stephen suggested is even more rigid, but maybe
not the most infrastructure-friendly approach ;-)

Cheers,
 
Y

Yas

Hello, thanks for your help but it is still not running the way I want.
I have tried:
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Intrader, you said: "Try an old trick: add a parameter that changes each time you submit". Would you give me please more detail about this trick? Where should I declare that parameter?

In order to make my question more crear I am including the general html structure of my main page:

body MS_POSITIONING="GridLayout"
form id="Form1" name="Form1" method="post" runat="server"
table width="80%" align="center"
tr
td
div id="MyFrameContainer"
SPAN id="ifrmConfigurePage1" runat="server" /SPAN
/div
/td
/tr
tr
td align="center"
INPUT id="Button1" type="button" value="Next" name="Button1" runat="server"
INPUT id="Hidden1" type="hidden" name="Hidden1" runat="server"
/td
/tr
tr
td
div id="MyFrameContainer1"
iframe id="myframe" name="myframe" frameBorder="0" width="100%" height="500%" runat="server"
/iframe
/div
/td
/tr
/table
/form
/body

As you can see I have an Iframe that I load with several versions of an html file. I Load these html files to the Iframe in the code behind.

Any suggestion will be welcome.
Thanks
Yas

From http://www.developmentnow.com/g/8_2004_11_0_0_4579/Turn-off-caching.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
E

Eliyahu Goldin

Intrader, you said: "Try an old trick: add a parameter that changes each
time you submit". Would you give me please more detail about this trick?
Where should I declare that parameter?

When you specify the url for your html file, do it like this:

'myFile.htm?'+(new Date()).getMilliseconds()

Eliyahu
 
J

Joerg Jooss

Yas said:
Hello, thanks for your help but it is still not running the way I
want. I have tried:
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);

So... what happens?

Cheers,
 
N

Nise

J

Joerg Jooss

Nise said:
Hi friends,

I am facing almost a similar problem.
But in my case, the html pages are getting cached whereas the asp
pages are getting executed afresh. The problem is only with some of
the html pages. And these pages are getting cached on the server(iis
5.0). Changing the HTTP header setting is of no effect!

What did you do exactly?

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top