的OutputCache属性在MVC 3被忽略 [英] OutputCache attribute being ignored in MVC 3

查看:198
本文介绍了的OutputCache属性在MVC 3被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有IE 7的问题能够从内置的MVC 3.对于IE 7能够从一个SSL网站保存文件的SSL站点下载文件时,它必须缓存能。

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.

在code的方法是:

[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时,持续时间和NoStore各种设置。当我过任何更改这些设置响应头似乎从来没有改变。

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的,没有店面,必重新验证

Cache-Control:no-cache, no-store, must-revalidate

内容处置:附件;文件名= PersonalInfo-02092012.xlsx

Content-Disposition:attachment; filename=PersonalInfo-02092012.xlsx

内容长度:11933

Content-Length:11933

内容类型:应用程序/ vnd.openxmlformats-officedocument.s preadsheetml.sheet

Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

日期:星期四,2012年2月9日十八时16分35秒GMT

Date:Thu, 09 Feb 2012 18:16:35 GMT

截止日期:-1

杂注:无缓存

服务器:Microsoft-IIS / 7.5

Server:Microsoft-IIS/7.5

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

我解决了这个一个自己,但我离开它在那里,这样它可能是利用别人。

I solved this one myself but am leaving it out there so that it may be of use to someone else.

问题是,定制ActionFilterAttribute是手动设置缓存信息并为此我在操作设置缓存中被忽略。

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.

相关的属性修剪简洁:

public class CustomAttributeName: ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var cache = filterContext.HttpContext.Response.Cache;
        cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        cache.SetValidUntilExpires(false);
        cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        cache.SetCacheability(HttpCacheability.NoCache);
        cache.SetNoStore();

        base.OnActionExecuting(filterContext);
    }
}

这篇关于的OutputCache属性在MVC 3被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆