在IIS7中,我有来自第三方的.ashx文件,该文件将缓存标头设置为no-cache,private
我希望将其缓存在客户端上,以便将以下代码添加到global.asax
void Application_EndRequest(object sender, EventArgs e)
{
if (Request.Path.IndexOf("Script.ashx") > -1)
{
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(DateTime.Now.AddDays(7));
Response.Cache.SetValidUntilExpires(true);
Response.Cache.VaryByHeaders["Accept-Language"] = true;
}
}
我希望生成的缓存信息为public, Expires: Thu, 29 Sep 2011 16:06:27 GMT
相反,我得到了no-cache,public Expires: Thu, 29 Sep 2011 16:06:27 GMT
因此,代码正在按照我的意愿将public替换为public,但它无法替换no-cache指令。是否可以用这种方法替换no-cache指令:如果是这样,我错过了什么;如果没有其他方法吗?
答案 0 :(得分:1)
上述代码在IIS7经典模式下失败,但集成模式代码按预期工作并产生合理的响应头。我认为这是由于经典的工作方式类似于ISAPI过滤器。我已切换到集成模式,这解决了这个问题。