实施asp.net的MVC静态文件缓存 [英] Implementing static files cache in asp.net mvc

查看:255
本文介绍了实施asp.net的MVC静态文件缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在ASP.net MVC应用程序静态文件缓存。

I am trying to implement static files cache in the ASP.net mvc application.

我所做的:

我已经加入到内容文件夹的web.config 文件包含以下内容:

I've added into Content folder a web.config file with the following content:

<?xml version="1.0"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="300.0:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

在网站的web.config 文件,我注释掉code的一些行:

In the website web.config file, i commented out some lines of code:

  <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" />
      <!-- Commented them out
      <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>

现在,发布网站和检查的资源,我得到了如下因素响应:

Now, publishing the website and inspecting the resources, i get the folowing response:

我看到的是缺少过期头?! (它不应该在那里,以便缓存工作)

I see is missing the Expire header ?! (shouldn't it be there in order for cache to work)

是否响应头告诉浏览器缓存资源为下25920000秒?

Does the response headers tell the browser to cache the resource for the next 25920000 seconds?

我在做正确的事情,以缓存静态文件?

I am doing things correctly in order to cache the static files?

推荐答案

这是正确的,你的应罚款

有些可能会说,你应该添加过期,也用于客户端的不理解的HTTP / 1.1,但如已经在href=\"http://www.mnot.net/blog/2007/05/15/expires_max-age\" rel=\"nofollow\">第一,这不应该是一个真正的问题,甚至更少现在7年过去了。

Some might say you should add Expires, too, for clients which do not understand HTTP/1.1, but as already argued in the first linked article, that shouldn't be a real concern, even less now, 7 years later.

这篇关于实施asp.net的MVC静态文件缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆