I follow this article to implement Custom Error Pages and Error Logging. The logging works fine. However, the custom error page doesn't display for ajax request when exception occured, it works for normal http full request, e.g.
http://localhost/MyApp/Report/Create/17/ , work, normal url request
http://localhost/MyApp/Report/CreateUser/17/json, NOT work, using Ajax
ASP.NET MVC HandleError Attribute, Custom Error Pages and Logging Exceptions
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);
}
}
web.config
<customErrors mode="On">
</customErrors>
Any idea would very much appreciated.