Several Methods for asp.net to capture globally unprocessed exceptions

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.