我有以下操作方法:
public class HomeController : Controller
{
[ProfileAction]
[CustomAction]
public string FilterTest()
{
//Does not get executed
return "This is the FilterTest action";
}
}
以下是过滤器的代码:
public class CustomActionAttribute : FilterAttribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
//This is executed first
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
//This is executed third
}
}
public class ProfileActionAttribute : FilterAttribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
//This is executed second
filterContext.Result = new HttpNotFoundResult();
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
//this does not execute
}
}
根据Microsoft,OnActionExecuted()
是在执行控制器动作后执行的。
从未调用动作方法FilterTest()
,因为我在ProfileActionAttribute.OnActionExecuting()
中设置了Result属性。
如果从未调用动作方法,为什么要调用CustomActionAttribute.OnActionExecuted()?