全局禁用缓存.NET

use*_*365 15 .net caching

有没有办法在ASP.NET中全局禁用服务器缓存?就像在web.config文件中添加某种设置一样?

到目前为止,我已经尝试添加这些并没有什么区别......

        <caching>
          <sqlCacheDependency enabled="false"></sqlCacheDependency>
            <outputCache enableOutputCache="false"
                enableFragmentCache="false"
                sendCacheControlHeader="false"
                omitVaryStar="false" />
        </caching>
Run Code Online (Sandbox Code Playgroud)

Stu*_*ver 13

如果您使用的是IIS7/7.5或IIS Express,还有一种在system.webServer中禁用此功能的方法.这将在您的主web.config文件(对于webforms和mvc)以及子文件夹中的web.config文件中工作,以便为应用程序的特定区域禁用它.

<system.webServer>
    <caching enabled="false" />
</system.webServer>
Run Code Online (Sandbox Code Playgroud)


Pra*_*ana 0

您可以通过删除整个应用程序的模块来禁用整个应用程序的输出缓存和会话状态,这可以从 web.config 中完成

<httpModules>
  <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
  <add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules>
Run Code Online (Sandbox Code Playgroud)

或者

将其添加到您的页面加载中

Response.Cache.SetCacheability(HttpCacheability.NoCache)
Run Code Online (Sandbox Code Playgroud)