我在Global.asax文件中响应Error事件:
protected void Application_Error(Object sender, EventArgs e)
{
Session["LastError"]=System.Web.HttpContext.Current.Server.GetLastError();
}
在web.config中作如下配置:
<customErrors mode="On" defaultRedirect="CustomErrorPage.aspx"/>
在我的自定义错误页CustomErrorPage.aspx上输出错误信息:
System.Exception ex=(System.Exception)Session["LastError"];
if(ex!=null)
Response.Write(ex.Message);
else
Response.Write("NO");
然后运行,在页上得到了这样的信息:
"发生类型为 System.Web.HttpUnhandledException 的异常。 "
但我出错页出的错误明明是"未将对象引用设置到对象实例"呀..而且ex.Source也得不到出错文件的描述.现在很疑惑:GetLastError()方法究竟返回了一个什么错误对象,显然这样的错误信息对于调试程序毫无帮助呀!
protected void Application_Error(Object sender, EventArgs e)
{
Session["LastError"]=System.Web.HttpContext.Current.Server.GetLastError();
}
在web.config中作如下配置:
<customErrors mode="On" defaultRedirect="CustomErrorPage.aspx"/>
在我的自定义错误页CustomErrorPage.aspx上输出错误信息:
System.Exception ex=(System.Exception)Session["LastError"];
if(ex!=null)
Response.Write(ex.Message);
else
Response.Write("NO");
然后运行,在页上得到了这样的信息:
"发生类型为 System.Web.HttpUnhandledException 的异常。 "
但我出错页出的错误明明是"未将对象引用设置到对象实例"呀..而且ex.Source也得不到出错文件的描述.现在很疑惑:GetLastError()方法究竟返回了一个什么错误对象,显然这样的错误信息对于调试程序毫无帮助呀!
谢谢,不过.我要的是ASP.NET环境下的呀...
HOW TO:使用 Visual C# .NET 在 ASP.NET 中创建自定义错误报告
http://support.microsoft.com/kb/306355/ZH-CN/