日期:2014-05-19  浏览次数:20480 次

VS2005里怎样自定义错误呀,出现错误都捕获转向统一的页面?按vs2003的方法为什么不行
web.config里:
<customErrors   mode= "On "   defaultRedirect= "Common/error.aspx ">
    <error   statusCode= "404 "   redirect= "Common/error.aspx "/>
</customErrors>

Global.asax里:
protected   void   Application_Error(Object   sender,   EventArgs   e)
{
    Exception   ex   =   Server.GetLastError().InnerException;
    Application[ "ErrorInfo "]   =   ex;
}

以上代码在vs2003里可以,vs2005就不行


------解决方案--------------------
下面是我现在的代码,可以用。
web.config中:
<customErrors mode= "On " defaultRedirect= "~\App\SystemError.aspx ">
</customErrors>

Global.asax中:
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
Application[ "ErrorInfo "] = ex;
}
------解决方案--------------------
我的好用,代码如下:

//Global.asax
<%@ Application Language= "C# " %>

<script runat= "server ">
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
Application[ "ErrorInfo "] = ex;
}

</script>

//webconfig
<customErrors mode= "On " defaultRedirect= "~\Exception.aspx "/>

//Exception.aspx

protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Application[ "ErrorInfo "].ToString());
}

//用于测试的页面
protected void Page_Load(object sender, EventArgs e)
{
int i = int.Parse( " ");
}