我想在项目处于生产( Release模式)时显示自定义错误页面,并在( Debug模式)运行页面时显示来自 asp.net 的默认错误页面。
我的项目中有三个 Web.config 文件。
- Web.config
- Web.Debug.config
- Web.Release.config
这是我尝试过的,但没有成功。
Web.config
<customErrors mode="On" defaultRedirect="~/Home/Error">
<error statusCode="404" redirect="~/Home/Error" />
</customErrors>
Web.Debug.config
<customErrors mode="Off" xdt:Transform="Replace"></customErrors>
Web.Release.config
<customErrors mode="On" defaultRedirect="~/Home/Error">
<error statusCode="404" redirect="~/Home/Error" />
</customErrors>
有人知道我该怎么做吗?
提前致谢:)
编辑: 阅读完后,我认为这是一个已知的错误,但我无法找到解决此问题的错误。如果有人对此有更多了解,请分享。谢谢
最佳答案
好的。所以我明白出了什么问题。
Web.config
<customErrors mode="Off" defaultRedirect="~/Error.htm"></customErrors>
Web.Debug.config
<compile debug="true" />
<customErrors mode="Off" xdt:Transform="Replace"></customErrors>
Web.Release.config
<customErrors mode="On" defaultRedirect="~/Error.htm" xdt:Transform="Replace">
<error statusCode="404" redirect="~/Error.htm" />
</customErrors>
上述更改将默认禁用错误消息,并且每当将项目部署到生产服务器上时,Web.Release.config
中的设置将覆盖默认的 Web.config
以下是我认为有用的资源/链接列表:
- Use Visual Studio web.config transform for debugging
- http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx
我希望这可以帮助其他正在尝试完成同样事情的人。
关于asp.net - "Release"模式下的自定义错误页面和 "Debug"模式下的默认错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12142545/