ASP.NET Global.asax Application_Error works, but not when using the Error event

I have an ASP.NET MVC application that should catch all unhandled exceptions in the global.asax application error handler.

If I define a handler as follows:

protected void Application_Error(object sender, EventArgs e)

then it works great. However, if in the Application_Start event I try to execute:

this.Error += new EventHandler(Application_Error);

The actual event is never called.

Does anyone know why and if so, what am I doing wrong?

+3
source share
2 answers

You do not need to explicitly add an error event; Application_Error should be automatically called through the framework.

+3
source

, - (, , ), , Application_Start ( ). - Application_Error:

protected void Application_Error(object sender, EventArgs e) {
  Exception exception = Server.GetLastError();
  // log exception
  // Email exception
}

, , , . , .

0

Source: https://habr.com/ru/post/1724007/


All Articles