Easy ( i hope): Error handling

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I added 2 kinds of error handling to my code:

In web.config , i have this

Code:
 <customErrors  defaultRedirect="ApplicationError.htm" mode="RemoteOnly" >
     <error statusCode="403" redirect="pages\Forbidden.htm"/>
     <error statusCode="404" redirect="NotFound.htm"/>
    
    </customErrors>

In Global.asax , I have this to log to even viewer:

Code:
 Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
        Dim unhandledException As Exception = Server.GetLastError().InnerException
        If Not EventLog.SourceExists("ESPWebClient") Then
            EventLog.CreateEventSource("ESPWebClient", "ESPWebClient Log")
        End If

        Dim el As EventLog = New EventLog()
        el.Source = "ESPWebClient"
        el.WriteEntry("An exception occured: Created an entry in the event log")
        'Server.ClearError()

    End Sub

I got an unhandeled error, But instead of loging to event viewer, the Custom Error in WebConfig popped up

Why didnt the application error in Global.asax fire??
 
use either one of the ways, either remove the custom errors and place the redirections in global.asax or remove the application_error event
they both do the same job
 
they both do the same job ...

No, i think they're different...

The Application_Error takes care of overall Application unhandled errors... So i think in this case, i think application_error should've fired..


I'm still not sure why, how the custom error fired ??
 
Back
Top