1

我正在尝试让 Asp.net 网站将静态文件缓存到浏览器客户端。

我按照这些步骤

我的网络配置:

<configuration>
  <!-- elements removed for readability -->

  <location path="content">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="100:00:00" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

但是,从文件夹中请求一个 js 文件Content并不会缓存该文件:

在此处输入图像描述

我做错了什么?我真的需要解决这个问题。

4

1 回答 1

0

从 web.config 中删除System.Web.StaticFileHandler配置解决了这个问题,但我不知道这是否是解决问题的正确方法:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

      <!--  Removing these rules makes the cache to work.
            With them, it doesn't work

      <add verb="GET" path="*.js" name="Static for js" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.css" name="Static for css" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.png" name="Static for png" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.jpg" name="Static for jpg" type="System.Web.StaticFileHandler" />
      -->
    </handlers>

    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="100:00:00" />
    </staticContent>
  </system.webServer>
于 2013-09-19T09:25:07.530 回答