IIS7 - 客户端缓存已具有无缓存数据集的 .ashx 文件
在 IIS7 中,我有一个来自第三方的 .ashx 文件,它将缓存标头设置为 no-cache,private
我希望将其缓存在客户端上,因此我将以下代码添加到全局.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 过期时间:2011 年 9 月 29 日星期四 16:06:27 GMT
因此,代码按照我的意愿将 private 替换为 public,但它无法替换 no-cache 指令。是否可以用这种方法替换 no-cache 指令:如果是的话,我错过了什么;如果不是还有什么其他方法?
In IIS7, I have a .ashx file from a third party which sets caching headers to be no-cache,private
I want this to be cached on the client so I have added the following code to the 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;
}
}
I would expect the resulting cache information to be public, Expires: Thu, 29 Sep 2011 16:06:27 GMT
Instead however I get the Franken-response of no-cache,public Expires: Thu, 29 Sep 2011 16:06:27 GMT
So the code is taking replacing the private with public as I want but it fails to replace the no-cache directive. Is it possible to replace the no-cache directive with this approach: if so what am I missing; if not what other approaches are there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的代码在 IIS7 经典模式下失败,但在集成模式下代码按预期工作并生成合理的响应标头。我认为这是由于 classic 的工作方式类似于 ISAPI 过滤器。我已切换到集成模式,这已经解决了问题。
The above code fails in IIS7 Classic mode but the Integrated mode the code works as expected and produces sensible response headers. I assume this is due to the way that classic works similar to an ISAPI filter. I have switched to Integrated mode and this has solved the issue.