我在Azure ASP.NET Web应用程序中有一个自定义错误页面,我想显示
<p>Oops - something went wrong.</p>
<p>The most common problem is that you tried to do something that the database enforces shouldn't happen.</p>
<p>The error is:</p>
在web.config中我有:
<customErrors mode="On" defaultRedirect="Error.aspx" />
和global.asax:
protected void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err = "Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +
"\nError Message:" + objErr.Message.ToString() +
"\nStack Trace:" + objErr.StackTrace.ToString();
EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error);
}
问题:如何在Error.aspx页面上显示完整的例外?
答案 0 :(得分:2)
如果您使用的是ASP.NET 3.5 SP1,请尝试将redirectMode="ResponseRewrite"
属性添加到customErrors
元素。这应该保留Server.GetLastError()
中存储的异常信息。然后,您可以在Error.aspx
页面添加标签并显示例外详情,即lblError.Text = Server.GetLastError().ToString()
。
以下是类似的问题:ASP.NET custom error page - Server.GetLastError() is null