开发者

Disable OutputCaching in MVC3 when running in DEBUG or under Debugger?

I am trying to disable output caching in a MVC3 app when in debug. I am specifying output caching in the controllers (via the attribute) but don't want to have to #if DEBUG all over my code. I expected this to work:

// In Web.config.debug
  <system.web>
    <caching>
      <开发者_开发问答;outputCache enableOutputCache="false"
                   xdt:Transform="Replace" />
    </caching>

But this seems to be ignored. Any other ideas how to do it system wide without nasty global.asax code or #if DEBUGs everwhere?


The web.config.debug file is used only when you build a deployment package. If you run your site locally in Cassini for example it is completely ignored. So you may try disabling cache in your web.config:

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

and in your web.config.release enable the cache. Note though that if you don't use the web deployment package feature those files are completely ignored.


I would think that would work as well. You may want to also try setting enableFragmentCache to false. Per this link:

the EnableFragmentCache property is set to false, no page is cached on the server, regardless of the settings in @ OutputCache directive or caching profile used by the page. For more information, see OutputCacheSettingsSection and OutputCacheProfile.


If you use IIS version > 7 You should:

  <system.webServer>
    <caching  enabled="true"/> //false in webconfig.debug
  </system.webServer>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜