2013-01-14 86 views
0
void Application_Error(object sender, EventArgs e) 
{ 
    Exception objException = Server.GetLastError().GetBaseException();   
    Server.Transfer("~/ErrorPage/Error_Page.aspx?objException=" 
         + objException,true); 
} 

//Error page.aspx page load 
protected void Page_Load(object sender, EventArgs e) 
{ 
    object objException = Request.QueryString["objException"]; 
    //Write exception in log file. 
    WriteApplicationErrorLog(objException.Message, objException.StackTrace); 
} 

我在应用程序级别上获取Global.asax中的异常对象。我需要这个例外对象传递给errorpage.aspx一个页面,并将其写入日志文件。如何通过查询字符串传递异常对象

我使用上面的代码,但得到的异常信息,而不是对象。

+0

为什么不在这个'Application_Error'中记录异常,然后*然后*重定向到错误页面? –

回答

1

可以使类和异常对象传递给它来记录它,但如果你想通过它的错误页面的任何方式,那么你可以在会议,并访问存储异常对象错误页面。

void Application_Error(object sender, EventArgs e) 
{  
    Session["YourException"] = Server.GetLastError().GetBaseException(); 
    Server.Transfer("~/ErrorPage/Error_Page.aspx?objException=" 
         + objException,true); 
} 

protected void Page_Load(object sender, EventArgs e) 
{ 
    Exception objException = (Exception) Session["YourException"]; 

    //Write exception in log file 
    WriteApplicationErrorLog(objException.Message, objException.StackTrace); 
} 
+0

没有会话是可能的 – lax

相关问题