IE9缓存动态页面

时间:2011-05-12 12:03:58

标签: asp.net caching internet-explorer-9

我正在开发一个动态Web应用程序(在IIS7上运行),它在除IE9之外的所有主流浏览器中都能正常运行。看起来,它几乎可以缓解一切,并且会导致很多问题,例如

  • 经常更改内容保持不变
  • 用户访问授权内容,然后注销,然后尝试返回受保护的内容并从缓存中获取!

我尝试用

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

但到目前为止没有运气......

3 个答案:

答案 0 :(得分:3)

我刚刚在MVC开发中遇到过这个问题。

我想禁用所有AJAX请求服务器端的缓存。

为此,我注册了以下全局过滤器。

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();
        }
    }
}

答案 1 :(得分:1)

你是在大量使用AJAX吗?确保每个AJAX请求都是唯一的,否则IE9将提供请求响应的缓存版本。

例如,如果您的AJAX请求网址通常如下所示: http://www.mysite.com/ajax.php?species=dog&name=fido

相反,为每个请求添加一个唯一值,以便IE不仅使用缓存的响应。在Javascript中执行此操作的最简单方法是每次发出请求时递增的变量:

var request_id = 0;

var request_url = "http://www.mysite.com/ajax.php?species=dog&name=fido&request_id="+request_id;
request_id++;

答案 2 :(得分:0)

尝试

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

此外,必读:http://support.microsoft.com/kb/234067

相关问题