有没有办法在我的 ASP.NET 应用程序中禁用单个 javascript 文件的缓存,而不禁用应用程序中任何其他文件的缓存?
它在 Azure 中的 IIS 7 上运行,所以对我来说,控制它的唯一选项似乎是在 Web 服务器标记内。
我目前使用以下配置,但这会禁用所有文件的缓存。
<modules runAllManagedModulesForAllRequests="true"/>
<staticContent>
<clientCache cacheControlMode="DisableCache"/>
</staticContent>
</system.webServer>
我只想禁用经常更改的单个 JavaScript 文件的缓存。
可能吗?
最佳答案
我刚刚偶然发现了这个问题;您可以使用以下命令禁用特定文件的缓存:
<configuration>
<location path="path/to/the/file">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
(注意该路径是相对于web.config文件的)
或者,将单个文件放在它自己的目录中,并为该目录提供它自己的 web.config,以禁用对其中所有内容的缓存;
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
[两者都在 Windows 7 上的 IIS7.5 上进行了测试,但您必须确认它在 Azure 上运行正常]
关于xml - 如何使用 weserver 配置设置在 IIS 7 中禁用单个文件的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3929284/