OutputCache.VaryByHeader 未在响应中生成 Vary 标头
我有这个操作方法:
[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
是如何 true 的,例如 filterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypes< /code> 为 false,但
Vary
标头始终显示 *。
我想知道唯一可能的值是否是作为 filterContext.HttpContext.Response.Cache.VaryByHeaders
属性列出的四个值,可能是吗?
干杯。
I have this action method:
[OutputCache(Duration = 2,
Location = OutputCacheLocation.Any,
VaryByHeader = "Accept-Charset")]
public ActionResult Index()
{
return View();
}
And the generated response is:
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
Why is the Vary
header showing an asterisk instead of Accept-Charset
?
OutputCacheAttribute
does have effect on the response, actually, the Expires
and Cache-Control:max-age=n
headers depends on the Duration
argument, and the Cache-Control:public
/private
/no-cache
depends on the Location
argument.
I have created a wrapper for OutputCacheAttribute
to see what is going on:
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();
}
}
The headers are not shown in the break, so probably what OutputCacheAttribute
does is configure HttpContext.Current.Response.Cache
.
I can see how filterContext.HttpContext.Response.Cache.VaryByHeaders.UserCharSet
is true, and for example filterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypes
is false, but the Vary
header always says *.
I am wondering if the only possible values are the four ones listed as properties of filterContext.HttpContext.Response.Cache.VaryByHeaders
, could it be?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是使用
Response.Cache.SetOmitVaryStar (true)
我仍在尝试找出该线程中 Vary:* 出了什么问题:HTTP 标头 Vary 的含义是什么:*
The solution is use
Response.Cache.SetOmitVaryStar(true)
I am still trying to figure out what is wrong with Vary:* in this thread: What is the meaning of the HTTP header Vary:*
<%@ OutputCache Duration="2000" VaryByParam="*" VaryByHeader="Accept-Language" %>
<%@ OutputCache Duration="2000" VaryByParam="*" VaryByHeader="Accept-Language" %>