I’m not seeing the real error in my custom error page when using an UpdatePanel. In my Global.asax I have the following code:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'Get the exception
Dim lastError = Server.GetLastError()
If lastError IsNot Nothing Then
Dim ex As Exception = lastError.GetBaseException()
If ex IsNot Nothing Then
'Log the error
If Log.IsErrorEnabled Then
log4net.ThreadContext.Properties("method") = ex.TargetSite.Name
log4net.ThreadContext.Properties("userId") = User.Current.UserName
Log.Error(ex.Message, ex)
End If
End If
End If
End Sub
If I review the log or set a breakpoint I can see that I’m getting a timeout issue. Then I have the following code to send the user to the error page and display the error:
<script language="javascript" type="text/javascript">
function EndRequestHandler(sender, args) {
if (args.get_error() != undefined) {
// Let the framework know that the error is handled,
// so it doesn't throw the JavaScript alert.
args.set_errorHandled(true);
var errorMessage = args.get_error().message.replace(/</gi, "<").replace(/>/gi, ">");
// If there is, show the custom error.
window.location = _root + 'ShowError.aspx?error=' + encodeURI(errorMessage)
}
}
</script>
But the error I’m getting from args.get_error() is this instead:
Sys.WebForms.PageRequestManagerServerErrorException:
An unknown error occurred while
processing the request on the server.
The status code returned from the
server was: 500
What do I have to do to get the timeout error to the error page?
I finally found it here: http://msdn.microsoft.com/en-us/library/bb398934.aspx
Although their example wouldn’t compile and didn’t give me exactly what I needed it got me in the right direction. I was able to control the message that gets put in the Async exception using this code:
I also had to remove the defaultRedirect in the web.config and only conditionally redirect if it was not an async call. I did that by changing my Global.asax to this: