asp.net – 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为false,但Vary标头总是说*. 我想知道唯一可能的值是否是作为filterContext.HttpContext.Response.Cache.VaryByHeaders属性列出的四个值,它可能是吗? 干杯. 解决方法
解决方案是使用
Response.Cache.SetOmitVaryStar(true)
[OutputCache(Duration = 2,VaryByHeader = "Accept-Charset")] public ActionResult Index() { Response.Cache.SetOmitVaryStar(true); return View("ShowHeaders"); } 我仍在试图弄清楚Vary有什么问题:*在这个帖子中:What is the meaning of the HTTP header Vary:* (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – URL长度的最佳限制是什么? 100,200
- asp.net – 数据库交互/业务逻辑在MVC中发生在哪里?
- asp.net – 如何结合ASP MVC 5和Emberjs
- asp.net-mvc – 将域映射到MVC区域
- asp.net – 如何通过webservice从返回的数据集中删除“diff
- asp-classic – ADODB.Field错误’800a0bcd’
- asp.net-mvc – 如何在ASP.NET MVC应用程序中使用多个视图引
- asp.net-core – 使用ASP.NET Core创建cookie
- 在ASP.NET应用程序中使用out-of-process会话状态的SQL Serv
- asp.net – 如何在回发后阻止关闭模态弹出窗口(ModalPopupE