在开发系统上禁用输出缓存

17

我在ASP.net MVC应用程序中使用OutputCache。由于开发过程中启用了OutputCache并不是很愉快,因此我想禁用开发系统(本地计算机和开发服务器)上的OutputCache。

最好的方法是什么?


出现了一个较新的重复问题,针对当您想要更改某些输出缓存但不是全部时的情况,提供了一个有趣的答案:使用缓存配置文件 - patridge
2个回答

19

这个问题很老了,但是...

在你的web.config文件的system.web标签下设置它。

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

这应该是false而不是true吧? - ashes999
@TonyBasallo 这在IIS Express 8上真的不起作用。为什么呢? - Freshblood

15
在ASP.NET中,可以使用以下方法启用和禁用输出缓存: 对于IIS版本<7.0:
<system.web>
    <caching>
        <outputCache enableOutputCache="false" />
    </caching>
</system.web>

对于iis版本>=7.0

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

注意:我通常会两者都使用,比起脚痛更安全,并使用配置转换确保在发布时启用不同配置的缓存。在我的解决方案中,一个配置与一个环境相对应

另一种技术是使用编译指示使代码片段能够编译或不编译,依据如DEBUG条件编译符号等:

#if DEBUG
    [OutputCache]
#endif

1
需要使用 IIS Express 8 的预先版本为 IIS 7。 - Jeff Walker Code Ranger
这两个示例(IIS7之前和之后)是针对不同功能的。<system.web> 中的示例是用于 ASP.NET OutputCache(https://learn.microsoft.com/en-us/iis/configuration/system.webserver/caching/)。而 <system.webServer> 中的示例则是用于内置的 IIS 响应缓存(https://learn.microsoft.com/en-us/iis/configuration/system.webserver/caching/)。IIS 缓存与 OutputCache 兼容。 - J. Christian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接