MVC 3 中忽略 OutputCache 属性
因此,我在 IE 7 能够从 MVC 3 内置的 SSL 站点下载文件时遇到问题。为了使 IE 7 能够从 SSL 站点保存文件,该文件必须是可缓存的。
该方法的代码是:
[OutputCache(Location = OutputCacheLocation.ServerAndClient, Duration = 20, VaryByParam = "none", NoStore = true )]
public override FileContentResult Export(int? id, string extra)
{
...
return new FileContentResult(byte[], mimetype);
}
这适用于 IE9、Chrome、Safari 和 Firefox。 我尝试了 VaryByParam、Duration 和 NoStore 的各种设置。当我更改任何这些设置时,响应标头似乎永远不会改变。
缓存控制:无缓存、无存储、必须重新验证
内容处置:附件;文件名=PersonalInfo-02092012.xlsx
内容长度:11933
内容类型:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
日期:2012 年 2 月 9 日星期四 18:16:35 GMT
过期:-1
编译指示:无缓存
服务器:Microsoft-IIS/7.5
任何帮助将不胜感激。
So I am having an issue with IE 7 being able to download a file from an SSL site built in MVC 3. For IE 7 to be able to save a file from an SSL site, it must be cache-able.
The code for the method is:
[OutputCache(Location = OutputCacheLocation.ServerAndClient, Duration = 20, VaryByParam = "none", NoStore = true )]
public override FileContentResult Export(int? id, string extra)
{
...
return new FileContentResult(byte[], mimetype);
}
This working in IE9, Chrome,Safari, and Firefox.
I have tried various settings for VaryByParam, Duration and NoStore. When ever I change any of those settings the response headers never seem to change.
Cache-Control:no-cache, no-store, must-revalidate
Content-Disposition:attachment; filename=PersonalInfo-02092012.xlsx
Content-Length:11933
Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date:Thu, 09 Feb 2012 18:16:35 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/7.5
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己解决了这个问题,但我把它留在那里,以便对其他人有用。
问题是自定义 ActionFilterAttribute 手动设置缓存信息,因此我在操作上设置的缓存被忽略。
为了简洁起见,对有问题的属性进行了修剪:
I solved this one myself but am leaving it out there so that it may be of use to someone else.
The problem was that a custom ActionFilterAttribute was manually setting the cache information and therefor the caching I was setting on the Action were being ignored.
The Attribute in question trimmed for brevity: