asp.net - "Release"模式下的自定义错误页面和 "Debug"模式下的默认错误页面

标签 asp.net asp.net-mvc web-config

我想在项目处于生产( 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

以下是我认为有用的资源/链接列表:

我希望这可以帮助其他正在尝试完成同样事情的人。

关于asp.net - "Release"模式下的自定义错误页面和 "Debug"模式下的默认错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12142545/

相关文章:

jquery - 使用 jQuery 设置 Html.TextBoxFor 值不会反射(reflect)在模型 POST 中

asp.net - 默认 Razor cshtml 命名空间在哪里定义?

asp.net - 如何修复 web.config 中重写部分的无效配置错误

c# - 在共享主机上使用 SQL Server 数据库

c# - 正则表达式没有从字符串中获取每个匹配项

asp.net-mvc - 在asp.net MVC中未命中自定义异常过滤器

c# - GoogleOAuth2AuthenticationOptions google+ API 关闭

c# - 我无法在 umbraco 中发送邮件

.net - 我可以在 VS2008 中使用 .NET Framework 4.0 吗?

asp.net - 身份验证后手动将属性添加到请求正文