为什么不调用IActionFilter.OnActionExecuted?

时间:2013-04-03 17:57:56

标签: asp.net-mvc asp.net-mvc-4

public class FirstActionAttribute : FilterAttribute, IActionFilter
{
    /* Is Called */
    public void OnActionExecuted(ActionExecutedContext filterContext)
    {}

    public void OnActionExecuting(ActionExecutingContext filterContext)
    {}
}

public class SecondActionAttribute : FilterAttribute, IActionFilter
{
    /* Isn't Called */
    public void OnActionExecuted(ActionExecutedContext filterContext)
    {}

    public void OnActionExecuting(ActionExecutingContext filterContext)
    {
           filterContext.Result = new ViewResult { ViewName = "NotIndex" };
    }
}

    [FirstAction(Order =1)]
    [SecondAction(Order=2)]
    public ActionResult Index()
    {
        return View();
    }

OnActionExecuted()被调用用于在设置OnActionExecuting()属性的操作过滤器之前调用Result的操作过滤器,因此取消了操作方法的执行。在我们的例子中,FirstAction.OnActionExecuted被调用,而SecondAction.OnActionExecuted没有被调用。

a)如果 FirstAction.OnActionExecuted动作方法从未执行过,那么调用Index的目的是什么?

b)无论如何,由于FirstAction.OnActionExecuted被调用,为什么不执行SecondAction.OnActionExecuted呢?

0 个答案:

没有答案