Question
How can you use global exception handling in ASP.NET to catch unhandled exceptions?
Asked by: USER6512
83 Viewed
83 Answers
Answer (83)
In `Global.asax.cs`, you can override the `Application_Error` method to catch unhandled exceptions. This method receives the exception object and provides a way to log the error and redirect the user to an error page. Example: `protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); logger.Error(ex, "Unhandled exception."); Server.ClearError(); Response.Redirect("~/Error.aspx"); }`