在ExceptionFilter之前调用Controller.OnException吗?

时间:2015-04-26 17:05:28

标签: c# asp.net-mvc

尝试在此处了解MVC管道:

似乎订单是这样的:

  1. AuthorizationFilters
  2. OnActionExecuting
  3. ActionExecutes
  4. OnActionExecuted
  5. OnResultExecuting
  6. 创建操作结果
  7. OnResultExecuted
  8. 写入回复流
  9. Controller.OnException何时相对于ExceptionFilterAttribute.OnException

    运行

1 个答案:

答案 0 :(得分:3)

它可能记录在某个地方,至少在源头,但我刚刚进行了这个小实验:

// in MyHandleErrorAttribute, globally configured
public override void OnException(ExceptionContext filterContext)
{
    Debug.Print("HandleErrorAttribute.OnException 1");
    base.OnException(filterContext);
    Debug.Print("HandleErrorAttribute.OnException 2");
}

...

// in HomeController
protected override void OnException(ExceptionContext filterContext)
{
    Debug.Print("Controller OnException 1");
    base.OnException(filterContext);
    Debug.Print("Controller OnException 2");
}

,输出窗口显示:

  

HandleErrorAttribute.OnException 1
  HandleErrorAttribute.OnException 2
  控制器OnException 1
  Controller OnException 2