Disable cache globally .NET

2019-01-26 04:29发布

is there a way to disable server caching globally in ASP.NET? Like by adding some sort of setting to the web.config file?

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>

标签: .net caching
4条回答
家丑人穷心不美
2楼-- · 2019-01-26 04:57

According to MSDN:

you can disable page output caching for the entire application by adding enableOutputCache="false" to the OutputCacheSection in your Web.config file.

e.g.

<configuration>
    <system.web>
        <caching>
            <outputCacheSettings enableOutputCache="false"/>
        </caching>
    </system.web>
</configuration>

So your configuration is not working because you have the enableOutputCache attribute on the outputCache element, when it should be on the outputCacheSettings element.

查看更多
何必那么认真
3楼-- · 2019-01-26 04:58

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.

<system.webServer>
    <caching enabled="false" />
</system.webServer>
查看更多
我想做一个坏孩纸
4楼-- · 2019-01-26 05:09

you can disable output caching and session state for the entire application by removing its modules , this can be done from 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)
查看更多
▲ chillily
5楼-- · 2019-01-26 05:23

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.config file. 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.

<system.web>
        <caching>
            <outputCache enableOutputCache="false"/>            
        </caching>
</system.web>
查看更多
登录 后发表回答