IE9 caching dynamic pages

我与影子孤独终老i 提交于 2019-12-09 20:08:08

问题


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


回答1:


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++;



回答2:


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:


Try

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

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



来源:https://stackoverflow.com/questions/5977673/ie9-caching-dynamic-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!