fra*_*lic 140 iis iis-7 caching web-config http-headers
我想在IIS7中为我的ASP.NET网站中的静态内容缓存设置规则.
我已经看过这些文章,详细介绍了如何使用以下<clientCache />元素web.config:
但是,此设置似乎全局适用于所有静态内容.有没有办法只为某些目录或扩展这样做?
例如,我可能有两个需要单独缓存设置的目录:
/static/images
/content/pdfs
是否有可能建立规则发送缓存头(max-age,expires基于扩展和文件夹路径等)?
请注意,我必须能够这样做,web.config因为我无法访问IIS控制台.
Kev*_*Kev 212
您可以在根目录中为整个文件夹设置特定的缓存标头web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!-- Note the use of the 'location' tag to specify which 
       folder this applies to-->
  <location path="images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>
或者您可以web.config在内容文件夹中的文件中指定这些:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
    </staticContent>
  </system.webServer>
</configuration>
我不知道内置机制来定位特定的文件类型.
Jef*_*tis 67
您可以基于每个文件执行此操作.使用path属性包含文件名
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <location path="YourFileNameHere.xml">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="DisableCache" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>
| 归档时间: | 
 | 
| 查看次数: | 111194 次 | 
| 最近记录: |