2011-09-28 50 views
4

我有這樣的動作方法的Vary頭部:OutputCache.VaryByHeader部未產生在響應

[OutputCache(Duration = 2, 
       Location = OutputCacheLocation.Any, 
       VaryByHeader = "Accept-Charset")] 
    public ActionResult Index() 
    { 
     return View(); 
    } 

並且將所生成的響應爲:

Cache-Control:public, max-age=2 
Content-Length:5164 
Content-Type:text/html; charset=utf-8 
Date:Wed, 28 Sep 2011 16:30:33 GMT 
Expires:Wed, 28 Sep 2011 16:30:35 GMT 
Last-Modified:Wed, 28 Sep 2011 16:30:33 GMT 
Server:Microsoft-IIS/7.5 
Vary:* 
X-AspNet-Version:4.0.30319 
X-AspNetMvc-Version:3.0 
X-Powered-By:ASP.NET 

爲什麼Vary頭表示一個星號代替Accept-Charset

OutputCacheAttribute確實能對反應的影響,實際上,ExpiresCache-Control:max-age=n頭依賴於Duration說法,和Cache-Control:public/private/no-cache依賴於Location說法。

我創建了一個包裝爲OutputCacheAttribute,看看是怎麼回事:

public class CustomOutputCacheAttribute:OutputCacheAttribute 
{ 
    public override void OnResultExecuted(ResultExecutedContext filterContext) 
    { 
     base.OnResultExecuted(filterContext); 

     Dictionary<String, String> headers = new Dictionary<string, string>(); 
     foreach (var header in filterContext.HttpContext.Response.Headers.AllKeys) 
      headers.Add(header, filterContext.HttpContext.Response.Headers[header]); 

     Debugger.Break(); 
    } 
} 

的標頭不以破出,所以大概是什麼OutputCacheAttribute確實是配置HttpContext.Current.Response.Cache

我可以看到filterContext.HttpContext.Response.Cache.VaryByHeaders.UserCharSet,例如filterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypes,但Vary頭總是說*

我想知道如果唯一可能的值是作爲filterContext.HttpContext.Response.Cache.VaryByHeaders屬性列出的四個可能嗎?

乾杯。

回答

0

<%@的OutputCache時間= 「2000」 的VaryByParam = 「*」 VaryByHeader = 「接受語言」 %>

+0

這是應該做什麼的?它也發送'Vary:*'頭文件。 – vtortola