カスタムエラーページとエラーログを実装するには、この記事に従ってください。ロギングは正常に動作します。ただし、例外が発生した場合、カスタムエラーページはajaxリクエストのために表示されません、通常のHTTPフルリクエストで動作します。カスタムエラーページ、Controller.OnExceptionによるエラーログ、ASP.NET MVC
http://localhost/MyApp/Report/Create/17/、仕事、通常のURL要求
http://localhost/MyApp/Report/CreateUser/17/json、仕事NOT、web.configファイル
<customErrors mode="On">
</customErrors>
任意のアイデアは非常に高く評価でしょうアヤックス
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);
}
}
を使用して。
多分このリンクの回答は役に立ちます:http://stackoverflow.com/questions/1171035/asp-net-mvc-custom-error-handling-application-error-global-asax?answertab=oldest#tab-top –