【问题标题】:How to continue standart Asp.net Mvc - Application Error Page如何继续标准 Asp.net Mvc - 应用程序错误页面
【发布时间】:2013-12-14 18:05:40
【问题描述】:

如果我的 mvc 应用程序在发布模式(发布模式)下运行,我会处理所有错误消息

但是当我在调试模式下工作时,我看不到标准 mvc 应用程序错误页面。

因为它重定向到位于共享文件夹中的 Error.cshtml。

我怎样才能看到(或重定向?)标准 mvc 错误页面?

    protected void Application_Error()
    {
        // ReSharper disable once RedundantAssignment
        // ReSharper disable once ConvertToConstant.Local
        bool isCustomErrorEnabled = false;

--#if(!DEBUG) isCustomErrorEnabled = true; --#endif

        // ReSharper disable once ConditionIsAlwaysTrueOrFalse
        if (isCustomErrorEnabled) //Context.IsCustomErrorEnabled
        {
            ShowCustomErrorPage(Server.GetLastError());
        }
        else
        {
            //in this line, I want to continue to show standart 
            // application error page which has error message and stack trace
        }

    }

更新 - 这是我的 Web.Config 文件;

  <system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<globalization uiCulture="auto" culture="auto" />
<customErrors defaultRedirect="/Home/OldLink" mode="On" redirectMode="ResponseRewrite">
  <!-- RemoteOnly : Specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host. This is the default value. -->
</customErrors>

【问题讨论】:

  • 查看 webconfig 并搜索自定义错误模式
  • 拉梅什,谢谢您的回答。但是我通过代码中的“#if(!DEBUG)”忽略了app.config中的那一行......

标签: c# asp.net-mvc asp.net-mvc-5


【解决方案1】:

MVC 4 默认支持使用 HandleError 属性处理错误,将您重定向到 Error.cshtml。

只需使用 customErrors mode="off" 更新您的 web.config

【讨论】:

    猜你喜欢
    • 2013-06-23
    • 2018-12-20
    • 2011-09-04
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多