Last post Sep 22, 2006 01:08 PM by ojm37
Sep 22, 2006 09:36 AM|delorenzodesign|LINK
I have an HttpModule to handle logging for my web application, but every error gets logged as the following:
Exception of type 'System.Web.HttpUnhandledException' was thrown.
Which is pretty useless when I know an actual exception was thrown.
Here's what I'm doing on my Application_Error event via my module:
1 Exception ex = HttpContext.Current.Server.GetLastError();
2 // Get the current user if logged in, returns empty Guid if not
3 Guid userId = GetUserIdOfLoggedInUser();
4 // Write the exception to the log
5 Guid errorId = LogFactory.WriteExceptionToLog(GetDatabaseConnectionString(), ex, userId);
What would be the reason that the exception always gets logged as that?
Sep 22, 2006 12:40 PM|ojm37|LINK
It's being reported that way because that's the object you've got. At the System.GetLastError, when there's an unhandled error inside the asp code, that is the error that's returned. To get to the
actual error, you have to drill down one more level.
Exception ex = HttpContext.Current.Server.GetLastError().InnerException;
That will return you the error at the code level.
Sep 22, 2006 01:02 PM|delorenzodesign|LINK
Sep 22, 2006 01:08 PM|ojm37|LINK