【问题标题】:What is a good ASP.NET MVC detailed error page example有什么好的 ASP.NET MVC 详细错误页面示例
【发布时间】:2012-05-18 08:13:41
【问题描述】:

我查看了一堆其他问题,寻找详细错误页面布局的绝佳示例,但没有找到任何东西。我相信很多人以前都做过。

要求 * 必须显示异常信息(类型、堆栈跟踪) * 如果可能,应显示表单值 * 应该显示导致问题的区域/控制器/操作

我想到的最好的是:

@model System.Web.Mvc.HandleErrorInfo
@{ViewBag.Title = "Error";}

<h2>Sorry, an error occurred while processing your request.</h2>
<p>Please copy and paste this entire page in an email to 
<a href="mailto:me@me.com?subject=Website%20Error">Me</a> 
along with any other information you can provide so we can
get this fixed ASAP!</p>
@if (Model != null) {
    <h1>@Model.Exception.GetType().Name<br />
        thrown in @Model.ControllerName @Model.ActionName</h1>

    <h2>Details</h2>
    <div>
        @Model.Exception.ToString()
    </div>
}

【问题讨论】:

    标签: asp.net-mvc model-view-controller error-handling


    【解决方案1】:

    为什么要他们通过电子邮件向您发送错误信息,包括我自己在内的许多人永远不会向您发送电子邮件。使用 ELMAH 之类的工具自动向您发送未处理异常的电子邮件并显示友好的错误页面。

    http://code.google.com/p/elmah/

    如果您想在发生错误时从用户那里获得反馈,您可以有一个文本框并要求他们向您提供有关他们在进入错误页面时所做的操作的信息,这似乎运作良好,这表明您正在积极主动地尝试解决解决方案。请务必说一些话,让他们知道您已收到通知,但您正在寻找其他信息以防止该错误在未来再次发生

    【讨论】:

    • 这就是我喜欢 StackOverflow 的原因。
    猜你喜欢
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多