The
application_error event is similar to the Page_Error event, and you can use him to catch errors that occur in the application. Because events occur throughout the application, you can log application error messages or handle other application-level errors that may occur
Asp. NET error handling Application_Error event examples are as follows: New Web Program--New AppEvent.aspx page--Add the following code to the page: code as follows: <script language=c# runat= "Server" > void Page_Load (object sender, System.EventArgs e) {throw (new ArgumentNullException ());} </SCRIPT> Then, add the Application_Error event to the Global.asax file to catch the error that was raised in the Page_Load event of the AppEvent.aspx page. Add the following code to the Global.asax file: The code is as follows: protected void Application_Error (object sender, EventArgs e) {Exception objerr = S Erver. GetLastError (). GetBaseException (); Get error keleyi.com String err = "Error caught in Application_Error event/n" + "error in:" + Request.Url.ToString () + "/nerro R message: "+ objErr.Message.ToString () +"/nstack Trace: "+ objErr.StackTrace.ToString (); Writes the caught error to the application log in Windows, where the application log can be accessed from the Event Viewer. System.Diagnostics.EventLog.WriteEntry ("Test2", err, System.Diagnostics.EventLogEntryType.Error); Server.ClearError (); Clears the exception, and the exception is no longer caught elsewhere. Save the action you just made, in Visual Studio. NET, on the Build menu, click Build. Right-click the page, and then click View in the browser. In this case, the page will be blank, butIs that you should notice that a new item has been added to the event log. This example generates an entry in the Application log to access the application log from the Event Viewer. After logging an error, you may want to redirect the user to another user-friendly error page or perform some other action as needed, which can be done according to your needs.