我有這樣的動作方法的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
確實能對反應的影響,實際上,Expires
和Cache-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
屬性列出的四個可能嗎?
乾杯。
這是應該做什麼的?它也發送'Vary:*'頭文件。 – vtortola