MvcApplication.Error Not Firing (global.asax)
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
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?
精彩评论