我有这个动作方法:
[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确实对响应有影响,实际上,ExpiresandCache-Control:max-age=n标头取决于Duration参数,而//Cache-Control:public取决于参数。privateno-cacheLocation
我创建了一个包装器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是 configure HttpContext.Current.Response.Cache。
我可以看到如何filterContext.HttpContext.Response.Cache.VaryByHeaders.UserCharSet是真的,例如filterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypes是假的,但Vary标题总是说*。
我想知道是否唯一可能的值是列为 的属性的四个值filterContext.HttpContext.Response.Cache.VaryByHeaders,可以吗?
干杯。