我一直在寻找有关如何在项目级别禁用客户端缓存的信息。 我知道我可以在操作方法之前添加以下内容:
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
我还阅读了一些有关为缓存创建配置文件的内容,但这也意味着在多个地方引用它们。我想在 web.config 或 IIS 中进行单一设置?
我正在从事的项目包含很多局部 View
预先感谢您就此事提供的任何建议。
最佳答案
您可以通过 Web.Config 禁用浏览器缓存:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache, no-store" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
来源:http://blog.jamesjones.name/2009/11/how-to-disable-browser-caching-in.html
编辑:添加no-store
至Cache-Control
适用于 Chrome ( http://code.google.com/p/chromium/issues/detail?id=28035 )
您可以在项目级别或子目录级别进行设置,以根据需要控制浏览器缓存。例如,在主要数据驱动/动态站点中,我可以在项目级别设置这些 header ,但在/static 目录(包含我的 .js、.css、图像)中,添加另一个 web.config,其中包括合适</clear>
指令,也许还可以设置一个 far-future-expires header 。
关于asp.net-mvc - 禁用客户端缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5496801/