我在ASP.net MVC应用程序中使用OutputCache。由于开发过程中启用了OutputCache并不是很愉快,因此我想禁用开发系统(本地计算机和开发服务器)上的OutputCache。
最好的方法是什么?
我在ASP.net MVC应用程序中使用OutputCache。由于开发过程中启用了OutputCache并不是很愉快,因此我想禁用开发系统(本地计算机和开发服务器)上的OutputCache。
最好的方法是什么?
这个问题很老了,但是...
在你的web.config文件的system.web标签下设置它。
<caching>
<outputCache enableOutputCache="false" />
</caching>
<system.web>
<caching>
<outputCache enableOutputCache="false" />
</caching>
</system.web>
对于iis版本>=7.0
<system.webServer>
<caching enabled="false" />
</system.webServer>
注意:我通常会两者都使用,比起脚痛更安全,并使用配置转换确保在发布时启用不同配置的缓存。在我的解决方案中,一个配置与一个环境相对应
另一种技术是使用编译指示使代码片段能够编译或不编译,依据如DEBUG条件编译符号等:
#if DEBUG
[OutputCache]
#endif
<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