我用的时候
Response.Cache.SetCacheability(HttpCacheability.Private)
和Response.Cache.VaryByHeaders["someValue"] = true;
响应中的Vary
标题缺少!
Response.Cache.SetCacheability(HttpCacheability.Public)
和Response.Cache.VaryByHeaders["someValue"] = true;
存在否问题。它返回Vary:someValue
使用web.config和控制器属性时的相同问题
添加name =" myCacheProfile"启用="真"持续时间=" 3600"的VaryByParam =" *" varyByHeader =" someValue中"位置="下游"工作并发送Vary标题
添加name =" myCacheProfile"启用="真"持续时间=" 3600"的VaryByParam =" *" varyByHeader =" someValue中"位置="客户"不起作用!
答案 0 :(得分:0)
如果您想使用自定义值,则必须在Global.asax.cs文件中执行覆盖:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (!string.IsNullOrEmpty(custom) && context != null && context.Request != null)
{
HttpRequest req = context.Request;
switch (custom.ToUpper())
{
case "someValue":
return req.someValue;
case "USER-AGENT":
if (req.UserAgent != null && req.Browser != null)
return req.UserAgent.ToString() + "-" + req.Browser.IsMobileDevice.ToString() + "-" + req.Browser.Platform;
else
return base.GetVaryByCustomString(context, custom);
default:
return base.GetVaryByCustomString(context, custom);
}
}
return base.GetVaryByCustomString(context, custom);
}