Tuesday, August 7, 2012

Handling Exceptions and 404 Errors in ASP.NET MVC

1. Add Customer error section in web.config file

    
    


2. Log exception in Application_Error event handler
void Application_Error(object sender, EventArgs e)
        {
            try
            {
                //Get the Error.
                Exception ex = Server.GetLastError();
                  Response.Redirect("~/YourErrorPage");
            }
            catch
            {
                //Response.Redirect("/oops.aspx");
            }
        }