IIS 7.5强制http标头CacheControl为私有

IIS 7.5强制http标头CacheControl为私有,iis,http-headers,iis-7.5,cache-control,integrated-pipeline-mode,Iis,Http Headers,Iis 7.5,Cache Control,Integrated Pipeline Mode,在.NET代码中,我有一个处理Http请求的自定义处理程序,在ProcessRequest方法中调用一个自定义HttpModule来设置Http缓存头 HttpModule使用以下代码在PreSendRequestHeaders方法中设置头 HttpCachePolicy cache = response.Cache; if (cache != null) { cache.SetCacheability(HttpCacheability.Public); cache.SetMaxAge(

在.NET代码中,我有一个处理Http请求的自定义处理程序,在ProcessRequest方法中调用一个自定义HttpModule来设置Http缓存头

HttpModule使用以下代码在PreSendRequestHeaders方法中设置头

HttpCachePolicy cache = response.Cache;
if (cache != null)
{
  cache.SetCacheability(HttpCacheability.Public);
  cache.SetMaxAge(TimeSpan.FromSeconds(varnishDuration));
  response.AppendHeader("Edge-control", String.Concat("!no-store, max-age=", akamaiDuration, "s dca=noop"));
}
<pre>
<system.webServer>
    <handlers accessPolicy="Read, Script">
      <add name="OxygenHandler" verb="*" path="*" type="com.eurosport.oxygen.server.modules.OxygenHandlerFactory, OxygenServerModules" />
    </handlers>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="WebServiceCachingModule" type="com.eurosport.toolkit.WebServiceCachingModule, Eurosport.Toolkit" />
    </modules>
  </system.webServer>
</pre>
在IIS 7.5中,当池处于集成模式时,CacheControl被强制为私有。 以下是我得到的:

curl -IXGET -H "Host:myHostName" "http://myServer/mypage"
HTTP/1.1 200 OK
Cache-Control: private
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Edge-control: !no-store, max-age=300s dca=noop
[...]
我不明白为什么IIS将CacheControl更改为private

以下是my web.config中的my webserver部分:



但是它没有帮助。

我已经设法让它在我的模块中使用以下代码:


它看起来很脏,但似乎response.CacheControl和response.Cache属性在集成模式下不被IIS使用(或被某些模块覆盖…)

默认值在以下内容中指定:

//
///    
///提供ASP兼容性。使用
///取而代之的是财产。
///    
/// 
公共字符串缓存控制{
得到{
如果(_cacheControl==null){
//默认值
返回“私有”;
}
返回缓存控制;
}
虽然您可以通过(全局)筛选器覆盖标头,但这不适用于由身份验证/授权引起的错误页面。幸运的是,每个请求都有一个很好的入口点,允许您覆盖此默认值:

//在Global.asax.cs中:
受保护的无效应用程序_BeginRequest()
{
Context.Response.CacheControl=“无缓存”;
}
更新:根据上述设置缓存控制将禁用捆绑包的缓存。我现在使用以下解决方法。它仅在未显式设置页面的缓存能力时更改页面的缓存能力。默认值“6”来自:

//在Global.asax.cs中:
受保护的无效应用程序\u EndRequest()
{
如果((int)Response.Cache.GetCacheability()==((int)HttpCacheability.ServerAndPrivate)+1)
Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
此外,当出现错误并且YSOD(黄色错误页)被呈现时,框架将调用,您的自定义缓存控制设置将被覆盖。我还没有找到解决方案

response.Headers.Remove("Cache-Control");
response.AppendHeader("Cache-Control", "public, max-age=" + varnishDuration.ToString()+", s-max-age=" + varnishDuration.ToString());