1

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

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

我想出的最好的是:

@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>
}
4

1 回答 1

5

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

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

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

于 2012-05-09T19:01:58.523 回答