如何使用 weserver 配置设置禁用 IIS 7 中单个文件的缓存 [英] How do I disable caching of an individual file in IIS 7 using weserver config settings

查看:12
本文介绍了如何使用 weserver 配置设置禁用 IIS 7 中单个文件的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在不禁用应用程序中任何其他文件的缓存的情况下禁用我的 ASP.NET 应用程序中单个 javascript 文件的缓存?

它在 Azure 中的 IIS 7 上运行,所以对我来说,控制它的唯一选项似乎是在网络服务器标签内.

我目前使用以下配置,但这会禁用所有文件的缓存.

 <静态内容><clientCache cacheControlMode="DisableCache"/></staticContent></system.webServer>

我只想禁用经常更改的单个 javascript 文件的缓存.

有可能吗?

解决方案

我刚刚偶然发现了这个问题;您可以使用以下内容禁用特定文件的缓存:

<预><代码><配置><location path="path/to/the/file"><system.webServer><静态内容><clientCache cacheControlMode="DisableCache"/></staticContent></system.webServer></位置></配置>

(注意路径是相对于web.config文件)

或者,将单个文件放在它自己的目录中,并为该目录提供自己的 web.config 以禁用其中所有内容的缓存;

<预><代码><配置><system.webServer><http协议><customHeaders><add name="Cache-Control" value="no-cache"/></customHeaders></http协议></system.webServer></配置>

[均在 Windows 7 上的 IIS7.5 上进行了测试,但您必须确认它在 Azure 上运行正常]

Is there any way to diable the caching of a single javascript file in my ASP.NET applicaiton without disabling the caching of any other files in the application?

It is running on IIS 7 in Azure, so to me it seems that my only options of controlling this are within the webserver tags.

I currently use the folowwing config, but this is disabling cache on all files.

     <modules runAllManagedModulesForAllRequests="true"/>

    <staticContent>
      <clientCache cacheControlMode="DisableCache"/>
    </staticContent>

  </system.webServer>

I just want to disable cache of a single javascript file that changes quite often.

Is it possible?

解决方案

I just stumbled across this question; you can use the following to disable the cache on a specific file:

<configuration>
  <location path="path/to/the/file">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

(Note that the path is relative to the web.config file)

Alternatively, place the single file in a directory on it's own, and give that directory it's own web.config that disables caching for everything in it;

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="no-cache" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

[Both tested on IIS7.5 on Windows 7, but you'll have to confirm that it works OK on Azure]

这篇关于如何使用 weserver 配置设置禁用 IIS 7 中单个文件的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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