0
我定義在ASP.NETcatch錯誤與Custome錯誤頁面
<customErrors mode="RemoteOnly" defaultRedirect="Oops.aspx"></customErrors>
當錯誤發生時,我被重定向到該頁面使用以下URL自定義錯誤頁:
Oops.aspx?aspxerrorpath=/WebForm1.aspx
在Oops.aspx
頁的Page Load
方法,我試圖捕獲錯誤:
Exception exc = Server.GetLastError();
if (exc != null)
{
//do something
}
但是,看起來exc
實際上是null
,因爲沒有在該條件語句中定義的操作正在執行。
如果您在數據存儲區中記錄錯誤,最好的方法是通過在Global.asax的Application_Error方法中記錄該錯誤,然後重定向到Oops.aspx?refId = yourerrorId'存儲在數據存儲區中的錯誤記錄的關鍵字。 – Nilesh
@Nilesh如何檢索在Global.asax中導致錯誤的頁面? –
@AliBassam http://stackoverflow.com/questions/344440/how-to-get-which-page-threw-an-exception-to-application-error-in-aspx –