如何正确应用全局动作过滤器,使其触发所有动作,然后返回触发过滤器的自定义动作结果?我将提供到目前为止我所做的事情的示例,但无法触发filterContext.Result = ...
全球.asax
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new RequestCounter());
}
public class RequestCounter : ActionFilterAttribute
{
public override void OnResultExecuted(ActionExecutingContext filterContext)
{
if (!LogCounter())
{
if (!filterContext.IsChildAction)
{
var values = new RouteValueDictionary(new
{
controller = "Account",
action = "LogOff"
});
filterContext.Result = new RedirectToRouteResult(values);
//--> Here, the action is not redirected to LogOff method,
// the goal is to logoff user, program just continues???
}
}
base.OnResultExecuted(filterContext);
}
}
如何从这个上下文中正确重定向到 LogOff() 方法,使用 Result 或其他方式?谢谢!