Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why global.asax Application_Error method does not catch exceptions thrown by ASMX service?

And how to fix it. I'd like to log every thrown exception for maintenance purpose.

like image 454
caustic Avatar asked Oct 17 '08 09:10

caustic


People also ask

How does ASP net handle application error global ASAX?

You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.

How does MVC handle application error in global ASAX?

Setting HandleError Attribute as a Global Filter Any unhandled exception that takes place within the boundary of the MVC application will now be handled by this global error handler. To test this global handler, comment out the [HandleError] attribute from the action or the controller and then run the application.


1 Answers

This is a known issue in .Net - Application_Error never fires for a web service. Not sure if there's any reason it would be by design, but it just doesn't work.

Jeff Atwood had a post (and follow-up) about this a few years ago, with the following ideas:

  • Put a try-catch block around each web service method
  • Use a facade design pattern and include the try-catch in parent objects
  • Write a custom SOAP extension or HTTPModule

The only one I care for is the first one, even though it seems like a lot of work.

like image 181
Raelshark Avatar answered Sep 19 '22 18:09

Raelshark