1. Capture unprocessed exceptions using HttpModule [recommended]
First, you need to define an HttpModule and listen for unprocessed exceptions. The Code is as follows:
+= context_Error( HttpContext ctx === Exception ex = Exception iex =
Then add the configuration information in web. config:
In this way, you can process the exceptions not handled in the webApp.
This method is recommended because it is easy to expand and universal. This method is also the most used.
2. Capture unprocessed exceptions in Global
There is an Application_Error method in Global. asax. This method is called when an unhandled exception occurs in the application. We can add the processing code here:
Application_Error( Exception ex = Exception iex = errorMsg = particular = (iex != ==== }
This method can also obtain the global unhandled exceptions. However, compared with the implementation of HttpModule, It is not flexible and general.
HttpModule takes precedence over Application_Error in Global.
3. Page-level exception capture
You can also add an exception handling method to the page: add the Page_Error Method to the Code on the page, which will process the unprocessed exception information on the page.
Page_Error( errorMsg ==+= += += + Request.Url + += + currentError.Message + }
This method takes precedence over HttpModule and Global.