2012-07-03 62 views
1

我的應用程序有一個自定義的HttpModule,我們用它來進行一些高級日誌記錄。它所做的只是爲HTTP響應添加一些自定義標頭。因HttpModule關閉客戶端緩存?

我遇到的問題是,當啓用此模塊時,.CSS文件將返回一個HTTP標頭Cache-Control: no-cache。當我關閉模塊時,我得到了我期待的是Cache-Control:max-age=2419200

我有使我的緩存:

<staticContent> 
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="28.00:00:00"/> 
</staticContent> 

我試圖註釋掉自定義標頭的添加在我們HttpModule,但沒有奏效。

此外,這隻會導致.CSS文件的問題。例如.JS,.PNG和.GIF都按我的預期工作。我似乎無法弄清楚爲什麼.CSS是特殊的。

不知道爲什麼只是讓該模塊導致緩存頭像那樣工作。有什麼想法嗎?

我在IIS7和IIS7.5上試過這個。 (實際上它運行在Windows Azure中,但我認爲這沒有什麼不同)。


編輯: web.config非常大。我不想把整個事情放在這裏。這裏是更多的:

<system.webServer> 
    <handlers> 
     <add name="pngHandler" path="*.png" verb="*" type="CompanyXXX.Applications.Portal.PngHttpHandler,Portal.System" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="" /> 
     <add name="gifHandler" path="*.gif" verb="*" type="CompanyXXX.Applications.Portal.GifHttpHandler,Portal.System" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="" /> 
     <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </handlers> 
    <modules> 
     <add name="CookieManagerModule" type="CompanyXXX.Web.CookieManagerModule, Framework.Web" preCondition="" /> 
     <add name="AuthenticationModule" type="CompanyXXX.Applications.Portal.AuthenticationModule,Portal.System" preCondition="" /> 
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" preCondition=""/> 
     <add name="LoggingModule" type="CompanyXXX.Applications.Portal.LoggingModule,Portal.System"/> 
     <add name="RequestReduce" type="RequestReduce.Module.RequestReduceModule, RequestReduce" /> 
    </modules> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false"/> 
    <httpCompression sendCacheHeaders="true"> 
     <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> 
    </httpCompression> 
    <staticContent> 
     <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="28.00:00:00"/> 
    </staticContent> 
</system.webServer> 

至於代碼,我不能發佈在這裏。我只能說,它只爲響應添加了3個頭文件。

+0

下的處理程序,你可以顯示模塊代碼(或東西的效果相同)和相關的XML配置經典模式? – orip

回答

0

我有類似的問題。

更改應用程序池pipelineMode到經典和u可以看到文件的響應頭的高速緩存控制最大年齡標籤。

你需要保持

 <system.Web><httpHandlers> <!--add here--></httpHandlers></system.Web>