public class CustomResultAttribute : FilterAttribute, IResultFilter
{
public void OnResultExecuted(ResultExecutedContext filterContext)
{}
public void OnResultExecuting(ResultExecutingContext filterContext)
{}
}
public class CustomActionAttribute : FilterAttribute, IActionFilter
{
public void OnActionExecuted(ActionExecutedContext filterContext)
{}
public void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.Result = new ViewResult { ViewName = "NotIndex" };
}
}
[CustomResult]
[CustomAction]
public ActionResult Index()
{
return View();
}
据我了解,结果过滤器应该只包含对action方法生成的结果进行操作的逻辑(因此我们将CustomResult
应用于特定的action方法)。
所以我不明白为什么在处理NotIndex
时也会调用结果过滤器,因为{em> NotIndex
不会生成Index
动作方法?
谢谢