禁用客户端缓存 [英] Disable client side caching

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

问题描述

我一直在搜索有关如何在项目级别上禁用客户端缓存的信息。
我知道我可以在操作方法之前添加以下内容:

I've been searching for info on how to disable client side caching on project level. I know I can add the following before an action method:

[System.Web.Mvc.OutputCache(NoStore = true,持续时间= 0,VaryByParam =*)]

我还阅读了有关为缓存创建配置文件的内容,但这也意味着引用他们在几个地方。我想在web.config中设置一个设置,或者在IIS中设置?

I also read something about making profiles for caching, but that would also mean refering to them in several places. I would like a single setting in web.config, or maybe in IIS?

我正在处理的项目包含很多部分视图

The project I'm working on contains a lot of partial views

提前感谢您对此事的任何建议。

Thank you in advance for any advice in this matter.

推荐答案

您可以禁用浏览器缓存通过Web.Config:

You can disable browser caching via 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 添加到Chrome的 Cache-Control http://code.google.com/p/chromium/issues/detail?id=28035

added no-store to Cache-Control for Chrome ( http://code.google.com/p/chromium/issues/detail?id=28035 )

您可以在项目级别或子目录级别设置此项,以根据需要控制浏览器缓存。例如,在主要数据驱动/动态站点中,我可以在项目级别设置这些头,但是在/ static目录(包含我的.js,.css,images)中,添加另一个web.config,其中包括适当的< / clear> 指令,可能会设置一个远期未来的过期标头。

You can set this at the project level or at the subdirectory level to control browser caching as desired. For example, in a primarily data-driven/dynamic site, I may set these headers at the project level, but in a /static directory (which contains my .js, .css, images), add another web.config which includes the appropriate </clear> directive, and perhaps set a far-future-expires header instead.

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

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