我的应用程序有一个自定义HttpModule
,我们用它来进行一些高级日志记录。它只是为HTTP响应添加了几个自定义标头。
我遇到的问题是,当启用此模块时,将返回.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 :(得分:0)
我遇到了类似的问题。
将应用程序池更改为pipelineMode为 Classic ,您可以在文件的Response标头中看到Cache control max age标记。
对于经典模式,您需要将处理程序保留在
下 <system.Web><httpHandlers> <!--add here--></httpHandlers></system.Web>