views:

90

answers:

1

Hi

The MvcApplication.Error event in my MVC application will not fire.

I have the following in web.config:

  <system.web>
   <customErrors mode="Off" />
   ...

And the following event defined in global.asax:

Public Sub MvcApplication_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error

    Dim lastErrorWrapper As HttpException = CType(Server.GetLastError(), HttpException)

    Using sw As New IO.StreamWriter("c:\test.txt")
        sw.WriteLine(lastErrorWrapper.StackTrace)
    End Using

End Sub

Obviously the above is massively simplified for the purposes of this question! In the end I will have it email the developers when an error occurs.

The problem is that this event will not fire, either in VS or when published to IIS.

Can anyone help?

Thanks in advance Jon

+1  A: 

There's no MvcApplication_Error event that gets called; rename that method to Application_Error and it'll fire as expected.

While you're in there, might I recommend eschewing rolling your own solution to this problem when ELMAH exists and is pretty easy to get up and running?

48klocs
Hi, surely the method name is irrelevant though because it's just an event handler, the important bit is "handles Me.Error".....I tried it anyway and it doesn't seem to make a difference.I will look into ELMAH but it may be overkill for what I need so I would still prefer to get the event to fire...any more ideas? Cheers for the help, I appreciate it
wheelibin