I'm implementing a custom page, and what I have now isn't working like I thought it would. How can I fix the code below to bubble up the full stack trace?
I'm using the Application_Error.
Thanks!
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>";
htt开发者_JAVA百科pContext.Response.Write(strError);
// clear the error
httpContext.Server.ClearError();
}
}
If you mean display the full stack trace in your HTML rendering, it can depend on how exceptions are caught and thrown within your application. If exceptions occur that you handle elsewhere in your application, and if in those instances you catch them, then throw a new exception, the use of httpContext.Server.GetLastError().InnerException may be useful to get the lower level stack trace.
When you catch and re-throw an exception, if you construct a new exception instance and pass the caught exception to the constructor of your new instance, you'll have that context available in your global error handler.
See http://msdn.microsoft.com/en-us/library/system.exception.innerexception.aspx
精彩评论