我有一个自定义异常过滤器属性:
public class RedirectOnErrorAttribute : FilterAttribute, IExceptionFilter {
#region IExceptionFilter Members
public void OnException(ExceptionContext filterContext) {
if(filterContext.ExceptionHandled) return;
filterContext.Controller.TempData["Exception"] = filterContext.Exception;
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new {area = "Desktop", controller = "Exception", action = "HandleError" }));
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 500;
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
}
#endregion
}
'ExceptionController' 的 Action 'HandleError' 包含一些业务逻辑。
在“HandleError”动作中
public ActionResult HandleError() {
Exception ex = (Exception)TempData["Exception"];
logger.Log(ex);
}
在 ex 变量中,我总是收到异常消息“执行处理程序 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper' 的子请求时出错。”
如何解决我的问题?