全局禁用缓存 .NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5550242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable cache globally .NET
提问by user441365
is there a way to disable server caching globally in ASP.NET? Like by adding some sort of setting to the web.config file?
有没有办法在 ASP.NET 中全局禁用服务器缓存?就像在 web.config 文件中添加某种设置一样?
So far I've tried adding these and it didnt make a difference...
到目前为止,我已经尝试添加这些,但没有任何区别......
<caching>
<sqlCacheDependency enabled="false"></sqlCacheDependency>
<outputCache enableOutputCache="false"
enableFragmentCache="false"
sendCacheControlHeader="false"
omitVaryStar="false" />
</caching>
回答by Stuntbeaver
There is also a way of disabling this in system.webServer if you are using IIS7/7.5 or IIS Express. This will work in your main web.config file (for both webforms and mvc) and also in web.config files in subfolders, to disable it for particular areas of your application.
如果您使用的是 IIS7/7.5 或 IIS Express,还有一种方法可以在 system.webServer 中禁用此功能。这将在您的主 web.config 文件(对于 webforms 和 mvc)以及子文件夹中的 web.config 文件中起作用,以在应用程序的特定区域禁用它。
<system.webServer>
<caching enabled="false" />
</system.webServer>
回答by Debashis chy
The OutputCacheSection section is used to configure application-scope settings, such as whether page output caching is enabled or disabled. For example, you can disable page output caching for the entire application by adding enableOutputCache="false"to the OutputCacheSection in your Web.configfile. Settings in the configuration file take precedence over cache settings in individual pages, so the example setting means that output cache will not be used.
OutputCacheSection 部分用于配置应用程序范围设置,例如是启用还是禁用页面输出缓存。例如,您可以通过添加enableOutputCache="false"到Web.config文件中的 OutputCacheSection来禁用整个应用程序的页面输出缓存。配置文件中的设置优先于各个页面中的缓存设置,因此示例设置意味着不会使用输出缓存。
<system.web>
<caching>
<outputCache enableOutputCache="false"/>
</caching>
</system.web>
回答by Pranay Rana
you can disable output caching and session state for the entire application by removing its modules , this can be done from web.config
您可以通过删除其模块来禁用整个应用程序的输出缓存和会话状态,这可以从 web.config 完成
<httpModules>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules>
or
或者
add this to your page load
将此添加到您的页面加载中
Response.Cache.SetCacheability(HttpCacheability.NoCache)
回答by UpTheCreek
you can disable page output caching for the entire application by adding enableOutputCache="false" to the OutputCacheSection in your Web.config file.
您可以通过将 enableOutputCache="false" 添加到 Web.config 文件中的 OutputCacheSection 来禁用整个应用程序的页面输出缓存。
e.g.
例如
<configuration>
<system.web>
<caching>
<outputCacheSettings enableOutputCache="false"/>
</caching>
</system.web>
</configuration>
So your configuration is not working because you have the enableOutputCacheattribute on the outputCacheelement, when it should be on the outputCacheSettingselement.
所以你的配置不起作用,因为你enableOutputCache在outputCache元素上有属性,而它应该在outputCacheSettings元素上。

