How can you use global exception handling in ASP.NET to catch unhandled exceptions?

Responsive Ad Header

Question

Grade: Education Subject: Support
How can you use global exception handling in ASP.NET to catch unhandled exceptions?
Asked by:
83 Viewed 83 Answers

Answer (83)

Best Answer
(429)
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"); }`