【发布时间】:2012-11-06 21:26:27
【问题描述】:
我正在尝试从 MVC4 移动应用程序显示自定义错误页面,但一直显示“错误加载页面”黄色消息而不是我的自定义页面。
我已尝试在动作和控制器上使用如下 HandleErrorAttribute,但没有成功
[HandleError(ExceptionType = typeof(SqlException), View = "DatabaseError")]
我也尝试过覆盖基本控制器的 OnException 方法,但这似乎也没有任何效果。
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext == null)
base.OnException(filterContext);
Logger.LogException(filterContext.Exception);
if (filterContext.Exception is SqlException)
{
filterContext.Result = new ViewResult { ViewName = "DatabaseError" };
}
if (filterContext.Exception is SomeOtherException)
{
filterContext.Result = new ViewResult { ViewName = "Error" };
}
if (filterContext.HttpContext.IsCustomErrorEnabled)
{
filterContext.ExceptionHandled = true;
filterContext.Result.ExecuteResult(this.ControllerContext);
}
}
如果我在非 jQueryMobile MVC4 应用程序上尝试这些方法,它们会按预期工作,只是在我的移动应用程序中不行!
任何人对为什么以及如何使这项工作有任何见解?
【问题讨论】:
标签: jquery-mobile asp.net-mvc-4