Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling 1

Status
Not open for further replies.

vwhite

Programmer
Oct 4, 2001
87
0
0
AU
I seem to be having an awful lot of trouble with error handling in ASP.NET when it should be pretty simple.

I have an Application_OnError Sub in the Global.asax file that sends the error message to me then redirects to the generic error page.

I also have the Custom Errors turned on in the web.config file which redirects to the same generic error page.

This works fine if I have a compilation error, but if I have a run time error the application_onError does not fire and it goes straight to the default error page.

Any help appreciated.

Cheers

Vicky....

"I used to have a handle on life...then it broke
 
Turn custom errors to Off in the web config.
Add a global.asax file to the project.
Capture the error handler like this:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Server.Transfer("errors.aspx")
End Sub

Add a page called errors.aspx and put this on page load.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s As String = Server.GetLastError.ToString

s = Server.HtmlEncode(s)
s = s.Replace(vbCrLf, "<br>")
If Not Request.Url.ToString.IndexOf(" 0, StringComparison.OrdinalIgnoreCase) = 0 Then
'Email the error to yourself here and hide from the end user
Else
'If localhost display it
Response.Write(s)
End If

End Sub
 
That tentatively seems to work although I am really unsure why the system has now decided to run the application_onerror event now that all it does is the Server.Transfer. Previously I had it sending an email then doing a Server.Transfer


However - from what I read I thought that the order of processing was
1. Try Catch Block
2. Page or Application on error event
3. defaultredirect in the web.config file

So I guess what you are saying is don't use the web.config default redirect and don't try and send the email from the global.asax file.

It seems really strange as I was following msdn doco I thought.

Vicky....

"I used to have a handle on life...then it broke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top