我的应用程序有一个自定义的 HttpModule
,我们使用它来进行一些高级日志记录。它所做的只是向 HTTP 响应添加几个自定义 header 。
我遇到的问题是,启用此模块时,返回的 .CSS 文件带有 Cache-Control: no-cache
的 HTTP header 。当我关闭模块时,我得到了我所期望的 Cache-Control:max-age=2419200
。
我启用了缓存:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="28.00:00:00"/>
</staticContent>
我尝试在 HttpModule
中注释掉添加自定义 header ,但这不起作用。
此外,这只会导致 .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 个 header 。
最佳答案
我也遇到过类似的问题。
将应用程序池的管道模式更改为经典,您可以在文件的响应 header 中看到缓存控制最大年龄标记。
对于经典模式,您需要将处理程序保留在
<system.Web><httpHandlers> <!--add here--></httpHandlers></system.Web>
关于asp.net - 由于 HttpModule 导致客户端缓存关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11319164/