2010-08-28 93 views
0

我在我的web.config中添加此:defaultRedirect跟蹤錯誤?

<customErrors mode="RemoteOnly" defaultRedirect="~/Site/Statics/Eroare.aspx"> 
      <error statusCode="404" redirect="~/Site/Index.aspx" /> 
     </customErrors> 

那麼,在Eroare.aspx頁面上Page_Load方法我嘗試打印我的內部日誌造成這種重定向,但Server.GetLastError錯誤()爲空...

你知道爲什麼嗎?或者任何其他解決方案來獲得例外?

謝謝。

回答

0

的關鍵是觸發在Global.asax中的錯誤文件

protected void Application_Error(object sender, EventArgs e) 
{ 
    Exception objErr = Server.GetLastError().GetBaseException(); 
    string err = "Error Caught in Application_Error event\n" + 
      "Error in: " + Request.Url.ToString() + 
      "\nError Message:" + objErr.Message.ToString() + 
      "\nStack Trace:" + objErr.StackTrace.ToString(); 
    EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error); 
    //Server.ClearError(); 
    //additional actions... 
} 

更多信息:http://support.microsoft.com/kb/306355