2012-02-09 29 views
2

所以我有一個問題,IE 7能夠從內置於MVC 3中的SSL站點下載文件。對於IE 7來說,能夠從SSL站點保存文件,它必須是可緩存的。在MVC中被忽略的OutputCache屬性3

用於該方法的代碼是:

[OutputCache(Location = OutputCacheLocation.ServerAndClient, Duration = 20, VaryByParam = "none", NoStore = true)] 
public override FileContentResult Export(int? id, string extra) 
{ 
... 
return new FileContentResult(byte[], mimetype); 
} 

該工作在IE9,鉻,Safari和Firefox瀏覽器。 我嘗試過VaryByParam,Duration和NoStore的各種設置。當我改變任何這些設置時,響應頭文件似乎永遠不會改變。

緩存控制:無緩存,沒有存儲,必須-重新驗證

內容處置:附件;文件名= PersonalInfo-02092012.xlsx

內容長度:11933

內容類型:應用/ vnd.openxmlformats-officedocument.spreadsheetml.sheet

日期:星期四,2012年2月9日18時16分: 35 GMT

截止日期:-1

雜注:無緩存

服務器:Microsoft-IIS/7.5

任何幫助,將不勝感激。

+0

有趣的 - 不知道這裏的IE行爲。我現在迴避IE的另一個原因是:http://support.microsoft.com/kb/323308 – 2012-02-09 20:28:34

回答

4

我自己解決了這個問題,但是把它放在那裏,這樣它可能對其他人有用。

問題在於自定義ActionFilterAttribute手動設置了緩存信息,因此我在Action上設置的緩存被忽略。

在修剪爲簡潔問題的屬性:

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