IIS 8.5 MVC5客户端缓存被忽略 [英] IIS 8.5 MVC5 Client Cache is ignored

查看:343
本文介绍了IIS 8.5 MVC5客户端缓存被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR - 我希望服务器(IIS 8.5)返回304不修改CSS和JS包

我一直无法得到IIS 8.5在web.config中兑现clientCache设置。无论我做什么,我似乎无法得到它的缓存静态内容。这是一个VS2013应用MVC5。我有一个文件夹资产中的所有静态文件。

请求是这样的:
http://someserver/AppName/Assets/mainjs?v=FNj_9ZPAbYVAQsyDo2F8XUnWv5NQpY4iX2RGu4NpJ5g1


  1. 尝试#1,放置在Assets文件夹中一个新的web.config文件与以下内容:


 <结构>
  < system.webServer>
    < staticContent>
      &所述; clientCache cacheControlMode =UseMaxAgecacheControlMaxAge =30.00:00:00/>
    < / staticContent>
  < /system.webServer>
< /结构>


<醇开始=2>

  • 尝试#2:发生在根web.config这下面的配置


  •  &LT; staticContent&GT;
        &所述; clientCache cacheControlMode =UseMaxAgecacheControlMaxAge =365.00:00:00/&GT;
    &LT; / staticContent&GT;


    <醇开始=3>

  • 尝试3:尝试使用位置标签设置缓存


  •  &LT;位置路径=资产&GT;
      &LT; system.webServer&GT;
        &LT; staticContent&GT;
          &所述; clientCache cacheControlMode =UseMaxAgecacheControlMaxAge =365.00:00:00/&GT;
        &LT; / staticContent&GT;
      &LT; /system.webServer>
    &LT; /地点&gt;


    下面是我在IIS 8.5经理企图的事。在默认Web站点/ TestApp


    1. HTTP Requeset接头,设置常见的HTTP标头,勾选过期Web内容经过365天(S)。

    2. 应用相同的设置的资产文件夹

    我已经试过所有这些步骤对自己和一起,每隔哪种方式。不管是什么,也不会添加最大年龄值缓存控制。

    有关每个这些中,browswer返回该CSS和JS捆200的响应。我不能让服务器缓存从Assets文件夹来的内容。

     缓存控制:私人
    内容编码:gzip
    内容长度:22591
    内容类型:text / CSS;字符集= UTF-8
    日期:星期一,2015年2月2日21时49分49秒GMT
    到期日:星期二,2016年2月2日21时49分49秒GMT
    最后一次修改:星期一,2015年2月2日21时49分49秒GMT
    持久验证:真
    服务器:Microsoft-IIS / 8.5
    有所不同:接受编码
    的X ASPNET-版本:4.0.30319
    的X已启动方式:ASP.NET


    解决方案

    检查该包的单个文件。做这些文件是什么样子,当你关闭的优化?之后您注册捆绑做出的电话:

      BundleTable.EnableOptimizations =(!HttpContext.Current.IsDebuggingEnabled);

      BundleTable.EnableOptimizations = FALSE;

    这可能是每一个文件是回来了不能修改。是否状态改变时,你刷新,而在调试会话?

    TL;DR - I want the server (IIS 8.5) to return 304 not modified for the CSS and JS bundles.

    I've been unable to get IIS 8.5 to honor the clientCache settings in web.config. No matter what I do, I can't seem to get it to cache the static content. This is a MVC5 app in VS2013. I've got all the static files in a folder "Assets".

    The request looks like: http://someserver/AppName/Assets/mainjs?v=FNj_9ZPAbYVAQsyDo2F8XUnWv5NQpY4iX2RGu4NpJ5g1

    1. Attempt #1, place a new web.config in the Assets folder with the following:

    <configuration>
      <system.webServer>
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
        </staticContent>
      </system.webServer>
    </configuration>
    

    1. Attempt #2: place this following configuration in the root web.config

    <staticContent>   
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />    
    </staticContent>
    

    1. Attempt #3: trying setting the cache using the location tag

    <location path="Assets">
      <system.webServer>
        <staticContent>
          <clientCache  cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
        </staticContent>
      </system.webServer>
    </location>
    

    Here are the things I've tried in IIS 8.5 manager. Under the Default Web Site/TestApp

    1. HTTP Requeset Headers, Set Common HTTP Headers, check "Expire Web Content" "After 365 Day(s)".
    2. Apply the same setting to the "Assets" folder

    I've tried these steps each on their own and all together and every other which way. No matter what, it won't add the max-age value to Cache-Control.

    For each of these, the browswer returns 200 responses for the CSS and JS bundles. I cannot get the server cache the content coming from the Assets folder.

    Cache-Control:private
    Content-Encoding:gzip
    Content-Length:22591
    Content-Type:text/css; charset=utf-8
    Date:Mon, 02 Feb 2015 21:49:49 GMT
    Expires:Tue, 02 Feb 2016 21:49:49 GMT
    Last-Modified:Mon, 02 Feb 2015 21:49:49 GMT
    Persistent-Auth:true
    Server:Microsoft-IIS/8.5
    Vary:Accept-Encoding
    X-AspNet-Version:4.0.30319
    X-Powered-By:ASP.NET
    

    解决方案

    Check the individual files of the bundle. What do the files look like when you turn off optimizations? After you register your Bundles make a call to :

    BundleTable.EnableOptimizations = (!HttpContext.Current.IsDebuggingEnabled);
    

    OR

    BundleTable.EnableOptimizations = false;
    

    It could be that each file is coming back with a not modified. Does the status change when you refresh while in a debug session?

    这篇关于IIS 8.5 MVC5客户端缓存被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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