问题描述
在我的web应用程序,我已经配置了我的web.config文件中设置的customErrors为ON,所以在这里它是:
On my web application, I had configured my web.config file to set customerrors to ON, so here it is:
<customErrors mode="On" defaultRedirect="Error.aspx">
<error statusCode="403" redirect="Error.aspx" />
<error statusCode="404" redirect="Error.aspx" />
</customErrors>
有关解释propouses我只抓住了403和404错误(和的defaultRedirect明显)。不过,我想获得页面上的错误的详细信息: Error.aspx
不知何故;但不创造各种错误的每一页。有没有一种办法,包括我的错误页面(Error.aspx)对某些code得到一个什么样提出,错误的详细信息?
For explaining propouses I only captured the 403 and 404 error (and the defaultRedirect obviously). But I would like to get more details of the error on the page: Error.aspx
somehow; but not creating each page for each kind of error. Is there a way to include certain code on my error page (Error.aspx) to get the detail of what raised that error?.
PD。我使用C#。
推荐答案
我想补充的谈话和应用别人已经建议,这是你如何使用什么门道建议显示在页面Error.aspx错误:
Just to add to the conversation and apply what others already suggested, this is how you can use what Mun suggested showing the error in the Error.aspx page:
protected void Application_Error(object sender, EventArgs e)
{
//Get last error
Exception ex = Server.GetLastError();
ex = ex.GetBaseException();
//display error to user
Context.AddError(ex);
Server.Transfer("Error.aspx", true);
}
在把这个code body标签中的Error.aspx页:
In the Error.aspx page put this code inside the Body tag:
<p>
<i><%= Context.Error.InnerException.Message.ToString() %></i>
</p>
这篇关于自定义错误处理Asp.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!