It's not scary for a website to be unusual, but the scary thing is that there is no logging.
Introduction to Global Exception Capture in MVC:
Global exception capture is a mechanism that Microsoft comes with in VS. In Asp.Net MVC, an exception filter HandleError feature is provided by default, which can be used to capture and handle exceptions thrown by controllers and operations, it will automatically detect errors running in the program, and get information about the errors. In the Asp.Net MVC, as long as the website throws an exception, it will trigger the Application_Error event in Global.asax, this method is used to catch exceptions, in this code we can add our business code (generally to record error logs and exception handling).
In MVC, you can also use the HandleErrorAttribute property tag to catch exceptions, which is mainly used for specific operation methods, and we rarely use it in writing projects. I won't introduce it to you here, if you want to know, Baidu is fine.
Introduction to custom exception capture in MVC:
In Asp.Net, not only can we use global exception capture, but Microsoft also provides us with a custom exception capture to meet our needs. Of course, in the custom exception capture, we still use this feature of HandleErrorAttribute provided by VS to implement it, and rewrite the OnException() method of HandleErrorAttribute in our own defined class to implement our business.
Review:
Code:
|