我正致力于这个Sitecore项目,并使用WebApi来执行一些服务调用。我的方法使用CacheOutput信息修饰,如下所示:
[HttpGet]
[CacheOutput(ClientTimeSpan = 3600, ServerTimeSpan = 3600)]我正在使用谷歌Chrome上的DHC应用程序测试这些调用。我确信ClientTimespan的设置是正确的,但是我要返回的响应头并不是我所期望的。我希望缓存控制的最大年龄为1小时,这是由ClientTimespan属性设置的,但是它被设置为私有的。

我已经调试了所有可能的东西,结果是Sitecore可能会拦截响应,并将这个头值设置为私有。我还将服务url添加到sitecore,忽略了url前缀配置,但没有帮助。
有没有人知道我怎样才能不改变我的Cache-Control头?
发布于 2014-06-27 08:27:37
这是默认的MVC行为,而不是直接与Sitecore / Web相关。
您可以创建一个自定义属性,该属性设置Cache-Control头:
public class CacheControl : System.Web.Http.Filters.ActionFilterAttribute
{
public int MaxAge { get; set; }
public CacheControl()
{
MaxAge = 3600;
}
public override void OnActionExecuted(HttpActionExecutedContext context)
{
context.Response.Headers.CacheControl = new CacheControlHeaderValue()
{
Public = true,
MaxAge = TimeSpan.FromSeconds(MaxAge)
};
base.OnActionExecuted(context);
}
}它使您能够将[CacheControl(MaxAge = n)]属性添加到方法中。
代码摘自:https://stackoverflow.com/questions/15911356/setting-http-cache-control-headers-in-webapi (答案2)
或者您可以在整个应用程序中全局应用它,如下面所解释的:http://juristr.com/blog/2012/10/output-caching-in-aspnet-mvc/
https://stackoverflow.com/questions/24445685
复制相似问题