0

在我的.NET代碼,我有處理的HTTP請求的自定義處理程序,並在processRequest方法調用一個自定義的HttpModule設置HTTP緩存頭。IIS 7.5的力量HTTP頭CacheControl設置私人

的HTTP模塊設置在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")); 
} 

在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設置專用。

這裏是我的web.config我的web服務器部分:

<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> 

我想這裏Cache.SetMaxAge not working under IIS, works fine under VS Dev Srv提到添加SetSlidingExpiration,但它並沒有幫助。

回答

0

我設法得到它與我的模塊下面的代碼工作:

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

它看起來髒髒的,但似乎response.CacheControl和response.Cache屬性不會在集成模式下使用IIS (或被某些模塊覆蓋...)