Create a global error handler
To create a global handler in a page, create a handler for the Page_Error event. To create an error handler for an application range, add the code to the Application_ERROR method in the global.asax file. These methods are called as long as you have unprocessed exceptions in your page or in your application. You can get information about the latest errors from the httpserverutility.getlasterror method. Note If you have a global error handler, it takes precedence over the error handles specified in the defaultRedirect property of the web.config customer. The following shows an example handler that gets information about the current error, put it in the session variable, and calls the general error handling page that can extract and display the error message.
'Visual BasicsUB Application_ERROR (Byval E AS Object, Byval E as Eventargs) Session ("currenteerror") = "Global:" & Server.getLastError.Message Server.Transfer ("lasterr.aspx") End Sub -------- -------------------------------------------------- -------------------------------------------------- -------------------
Web.config
In the web.config file of the application, the CustomerrorS elements are changed below: Set the Mode property to Remoteonly (case sensitive). This is configured to display a detailed error only to local users (you and developers). (Optional) includes the defaultRedirect property pointing to the application error page. (Optional) Includes
Web.config settings
Add the following code to the global.asax file: imports system.diagnostics
Sub Application_Error (ByVal sender As Object, ByVal e As EventArgs) Dim objErr As Exception = Server.GetLastError (). GetBaseException () Dim err As String = "Error Caught in Application_Error event" & _System.Environment.NewLine & _ "Error in : "& Request.url.toString () & _system.environment.newline & _" Error Message: "& jTEM.MESSAGE.TOSTRING () & _system.environment.Newline & _" Stack TRACE: "& Objerr.stackTrace.toString () EventLog.WriteEntry ("Sample_WebApp", ERR, EVENTLOGENTRYTYPE.Error) Server.clearerror () 'Additional Actions ... End Sub Save the Global.asax file.