title: Custom Error Pages, Error Logging via Controller.OnException override, ASP.NET MVC
body: <p>I follow this article to implement Custom Error Pages and Error Logging. The logging works fine. However, <strong>the custom error page doesn't display for ajax request</strong> when exception occured, it works for normal http full request, e.g.</p>
  
  <p><a href="http://localhost/MyApp/Report/Create/17/" rel="nofollow">http://localhost/MyApp/Report/Create/17/</a>  , work, normal url request</p>
  
  <p><a href="http://localhost/MyApp/Report/CreateUser/17/json" rel="nofollow">http://localhost/MyApp/Report/CreateUser/17/json</a>, NOT work, using Ajax</p>
  
  <p><a href="http://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html" rel="nofollow">ASP.NET MVC HandleError Attribute, Custom Error Pages and Logging Exceptions</a></p>
  
  <pre><code> public class BaseController : Controller
      {
  
   protected override void OnException(ExceptionContext filterContext)
          {
              base.OnException(filterContext);
  
              _log.Error("Error Logging", filterContext.Exception);
  
              // Output a nice error page when customErrors's mode = On.
              if (filterContext.HttpContext.IsCustomErrorEnabled)
              {
                  filterContext.ExceptionHandled = true;               
                  this.View("Error").ExecuteResult(this.ControllerContext);
              }
          }
  }
  
      public class MvcApplication : System.Web.HttpApplication
      {
          public static void RegisterGlobalFilters(GlobalFilterCollection filters)
          {
              //Display custom error page using controller.OnException(), HandleErrorAttribute has to be disabled.
             //filters.Add(new HandleErrorAttribute());
          }
  
    protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
  
              RegisterGlobalFilters(GlobalFilters.Filters);
              RegisterRoutes(RouteTable.Routes);
  
  
          }
  }
  </code></pre>
  
  <p>web.config</p>
  
  <pre><code>&lt;customErrors mode="On"&gt;
  
      &lt;/customErrors&gt;
  </code></pre>
  
  <p>Any idea would very much appreciated.</p>