IE9 caching dynamic pages

2019-04-13 10:11发布

I'm developing a dynamic web application (running on IIS7), it works fine in all the major browsers, except IE9. It seems, that it caches practically everything, and that leads to quite many problems, like

  • Often changing contents remain unchanged
  • User visits an authorized content, then signs out, then tries to go back to the secured content and gets it from cache!

I've tried disabling cache with

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

but no luck so far...

3条回答
祖国的老花朵
2楼-- · 2019-04-13 10:18

I've just come across this in an MVC development.

I wanted to disable caching of all AJAX requests server side.

To do this I registered the following global filter.

public class AjaxCacheControlAttribute:  ActionFilterAttribute
{
    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
        {
            filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
            filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();
        }
    }
}
查看更多
仙女界的扛把子
3楼-- · 2019-04-13 10:24

Try

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

Also, required reading: http://support.microsoft.com/kb/234067

查看更多
Lonely孤独者°
4楼-- · 2019-04-13 10:35

Are you making heavy use of AJAX? Make sure each AJAX request is unique, otherwise IE9 will serve up a cached version of the request response.

For example, if your AJAX request URL normally looks like: http://www.mysite.com/ajax.php?species=dog&name=fido

Instead, add a unique value to each request so IE doesn't just use the cached response. The easiest way to do that in Javascript is a variable that increments each time you make a request:

var request_id = 0;

var request_url = "http://www.mysite.com/ajax.php?species=dog&name=fido&request_id="+request_id;
request_id++;
查看更多
登录 后发表回答