开发者

Page doesn't un-cache itself in ASP.NET C#

I sometimes find that I need to press CTRL+REFRESH BUTTON (or simply REFRESH BUTTON) in order for pag开发者_运维问答es to be updated. I thought this may have been a problem with using AJAX Update Panel and things, but it also happens on pages where there is no AJAX partial rendering. I have also removed if(!isPostBack), and yet still I need to refresh the page for the contents to be updated.

Is it to do with the cache?

Does anyone know of a fix for this? I believe it only happens with IE 7 (which I am using). I tried the same feature with Chrome, and it worked as it is supposed to.

EDIT: Unfortuanetly, it is not as easy as setting to cache header to 0 or in IE retriving the latest page always on page load. I have done these and the same problem happens.

For instance, on one part of my site, you can change the profile picture. If I choose to remove the profile picture (which should then set to the default picture), it only deletes the picture (but doesnt display the default picture). The page loads again but it still references to the picture I deleted (so I get an X for the picture). I have to go onto a different page, and then back to the profile page for me to see the default picture. CTRL + REFRESH also works.

Note that this particular problem happens under all browsers (Chrome included).

If it helps, I am using Content pages which are in a master page.


Changing your browser cache settings will fix the problem locally, but to fix it for a general case, add the header "Expires: 0" to your outbound page, which will prevent browsers from caching it at all.

To do this in C#, add this code to the page load event:

Response.AddHeader("Expires", "0");


Ctrl+refresh forces you IE to reload page from server instead of using locally cached version. First, check your browser's settings: Settings - General - Browsing history. "Check for newer versions of stored pages" should be set to "Automatically". Then, check if you're adding any "expires" header to your pages.


You can also consider setting the caching policy on the response object or set the entity tag to something different every time...

http://msdn.microsoft.com/en-us/library/system.web.httpcachepolicy.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜