什么是一个很好的ASP.NET MVC详细错误页面示例

Jas*_*ver 1 error-handling model-view-controller asp.net-mvc

我查看了一些其他问题,寻找一个详细的错误页面布局的一个很棒的例子,但没有找到任何东西.我相信很多人以前都做过这件事.

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

我想出的最好的是:

@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>
}
Run Code Online (Sandbox Code Playgroud)

Ant*_*haw 5

为什么要求他们通过电子邮件向您发送错误,包括我在内的很多人都不会向您发送电子邮件 使用类似ELMAH的内容自动通过电子邮件发送未处理的异常并显示友好的错误页面.

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

如果您希望在发生错误时从用户那里获得反馈,您可以拥有一个文本框,并要求他们向您提供有关他们在错误页面上登陆时所执行操作的信息,这看起来效果很好,它表明你正在积极尝试解决问题.请务必说些什么让他们知道您已收到通知,但您正在寻找其他信息以防止错误再次发生