1

I am trying to make Asp.net website to cache static files to the browser client.

I followed these steps

My web config:

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

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

However, requesting a js file from the Content folder does not cache the file:

enter image description here

What i am doing wrong? I really need to fix this problem.

Community
  • 1
  • 1
Catalin
  • 11,503
  • 19
  • 74
  • 147

1 Answers1

0

Removing System.Web.StaticFileHandler configurations from web.config fixed the issue, but i don't know if this is the correct way to solve the problem:

<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>
Catalin
  • 11,503
  • 19
  • 74
  • 147