2010-08-28 91 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