Disable OutputCache on Development System

╄→尐↘猪︶ㄣ 提交于 2019-12-20 18:00:39

问题


I use OutputCache in an ASP.net MVC application. As developing with an active OutputCache is not very pleasant I want to disable the OutputCache on the Development Systems (local machines and development server).

What is the best way to do this?


回答1:


It's an old one but...

set this in your web.config under system.web

<caching>
  <outputCache enableOutputCache="false" />
</caching>



回答2:


The outputcache in ASP.NET can be enabled and disabled using

For iis versions < 7.0

<system.web>
    <caching>
        <outputCache enableOutputCache="false" />
    </caching>
</system.web>

For iis versions >= 7.0

<system.webServer>
    <caching enabled="false" />
</system.webServer>

N.B. I usually use both, better safe than having a sore foot, and use a config transform to make sure that the caching is enabled for different configurations on publish. In my solution a configuration corresponds 1 on 1 with an environment

Another technique is to use pragmas to enable pieces of code to compile or not compile based on i.e. the DEBUG conditional compilation symbol:

#if DEBUG
    [OutputCache]
#endif


来源:https://stackoverflow.com/questions/2788376/disable-outputcache-on-development-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!