问:
我使用ELMAH
- 错误记录模块和处理程序。
但我想向用户显示漂亮的错误页面。
我的问题有两个部分:
此页面是否需要任何首选设计或信息。(要求)。任何建议,链接都会很棒。
当我评论该
Clear error
行时,会向用户显示错误页面,否则不会出现错误页面。为什么我们要清除错误?以及如何显示错误页面。
protected void Application_Error(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString() +
"<br>Source: " + exception.Source +
"<br>Message: " + exception.Message +
"<br>Stack trace: " + exception.StackTrace;
ErrHandler.WriteError(errorInfo);
ctx.Server.ClearError();
}
<customErrors mode="On" defaultRedirect="Error.aspx"/>