2011-08-19 33 views
1

冒泡完整的堆栈跟踪误差,我实现自定义的页面,我现在不工作像我想的那样。我如何修复下面的代码来冒泡完整的堆栈跟踪?从Global.asax中

我使用的Application_Error。

谢谢!

EventLog eventLog = new EventLog(); 

      //Write an error to event log 
      eventLog.LogException(
       String.Format("UNHANDLED EXCEPTION\nPage: {0}", ((Global)(sender)).Context.Request.Path), 
       ex); 

      HttpContext httpContext = HttpContext.Current; 

      // Exception exception = httpContext.Server.GetLastError(); 

      //build out custom formatted error page 
      string strError = "<html>" + 
       "<head runat='server'>" + 
       "<title>Support Error Page</title>" + 
       "<link href='Styles/errorPage.css' rel='stylesheet' type='text/css' media='screen' />" + 
       "<script src='js/jquery.min.js' type='text/javascript'></script>" + 
       "<script src='js/expand.js' type='text/javascript'></script>" + 
       "<script type='text/javascript'>" + 
        "$(function() {" + 
         "$('#outer h2.expand').toggler({method: 'slideFadeToggle'});" + 
        "});" + 
       "</script>" + 
       "</head>" + 
       "<body>" + 
        "<form id='form1' runat='server'>" +      
          "<div id='wrapper'> " + 
           "<div id='content'>" + 
            "<h1 class='heading'>An error occurred processing this request</h1>" + 
             "<div id='outer'>" + 
             "<h2 class='expand'>Click here to expand/collapse the error</h2>" + 
             "<div class='collapse'>" + 
              "<p><b>Error occurred in page: </b>" + httpContext.Server.GetLastError().Source.ToString() + "</p>" + 
              "<p><b>Error Message: </b>" + httpContext.Server.GetLastError().Message.ToString() + "</p>" + 
              "<p><b>Stack Trace: </b>" + httpContext.Server.GetLastError().StackTrace.ToString() + "</p>" + 
             "</div>" + 
             "</div>" + 
            "</div>" + 
           "</div>" +        
        "</form>" + 
        "</body>" + 
        "</html>"; 

      httpContext.Response.Write(strError); 

      // clear the error 
      httpContext.Server.ClearError(); 
     } 
    } 
+2

为什么?有什么问题? – SLaks

回答

0

如果你的意思是显示在你的HTML渲染完整的堆栈跟踪,它可以依靠的例外是如何捕获你的应用程序中抛出。如果发生异常,你在你的应用程序的其他地方处理,如果在这些情况下,你抓住他们,然后抛出一个新的异常,使用httpContext.Server.GetLastError()的InnerException的可能是让较低级别的堆栈跟踪有用。

当你赶上并重新抛出异常,如果你建立一个新的异常情况,并通过捕获异常到新实例的构造函数,你必须在你的全局错误处理程序可用的情况下。

请参阅http://msdn.microsoft.com/en-us/library/system.exception.innerexception.aspx