I am simply trying to output the details of the application error on my error page. In global.asax I have some handling and then a server.transfer to my page with this code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Get exception details
Dim ex As Exception = HttpContext.Current.Server.GetLastError()
If TypeOf ex Is HttpUnhandledException AndAlso ex.InnerException IsNot Nothing Then
ex = ex.InnerException
End If
If ex Is Nothing Then
lblError.Text = "<p>An unknown error occurred.</p>"
Else
'Determine what type of error we're dealing with
If TypeOf ex Is System.Data.SqlClient.SqlException Then
'A database-related exception...
lblError.Text = String.Format("<p>The database is having problems... please try your submission again later.<br />{0}</p>", ex.Message)
ElseIf TypeOf ex Is ApplicationException Then
'An ApplicationException has occurred
lblError.Text = String.Concat("<p>An application fault has been tripped:<br /> {0}</p>", ex.Message)
Else
'For all others, display the StackTrace
lblError.Text = String.Format("<p>An unknown error occurred. The following dump of exception information can be used to diagnose the issue</p><p class=""stackTrace""><strong>Exception:</strong> {0}</p><p class=""stackTrace""><strong>Message:</strong> {1}</p><p class=""stackTrace""><strong>Stack Trace:</strong><br />{2}</p>", ex.GetType().ToString(), ex.Message, ex.StackTrace.Replace(System.Environment.NewLine, "<br />"))
End If
End If
End Sub
Locally it works great. When I deploy to our Windows Server 2008 machine running IIS 7, the condition for ex is nothing is tripped every time. I'm guessing that this issue is related to the IIS version - simply because I saw a few other posts along those lines, but no solutions. If anyone has thoughts as to how I may accomplish my error message dump, I'd appreciate it. I would like to know why this is happening also. I mean, a fix is great but I am curious as to why.