在DEBUG或Debugger下运行时,在MVC3中禁用OutputCaching?

时间:2011-03-13 02:30:38

标签: asp.net-mvc-3

我正在尝试在调试时禁用MVC3应用程序中的输出缓存。我在控制器中指定输出缓存(通过属性),但不想在我的代码中使用#if DEBUG。我希望这可行:

// In Web.config.debug
  <system.web>
    <caching>
      <outputCache enableOutputCache="false"
                   xdt:Transform="Replace" />
    </caching>

但这似乎被忽略了。系统范围内如何在没有令人讨厌的global.asax代码或#if DEBUGs的情况下进行任何其他想法?

3 个答案:

答案 0 :(得分:32)

web.config.debug文件仅在您构建deployment package时使用。例如,如果您在Cassini中本地运行您的站点,则会完全忽略它。因此,您可以尝试在web.config中禁用缓存:

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

并在web.config.release启用缓存。请注意,如果您不使用Web部署包功能,则会完全忽略这些文件。

答案 1 :(得分:0)

我认为这也会奏效。您可能还想尝试将enableFragmentCache设置为false。每this link

  

EnableFragmentCache属性是   设置为false,没有页面缓存在   服务器,无论设置如何   @ OutputCache指令或缓存   页面使用的配置文件。更多   信息,见   OutputCacheSettingsSection和   OutputCacheProfile。

答案 2 :(得分:0)

如果使用IIS版本> 7 您应该:

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