我有这个自定义操作过滤器:
public class PermissionChecker: ActionFilterAttribute
{
private int _permissionId { get; set; }
private IUserSelectorService _userService { get; set; }
public PermissionChecker(int permissionId)
{
_permissionId = permissionId;
_userService = new UserSelectorService();
}
public PermissionChecker(int permissionId, IUserSelectorService userService)
{
_permissionId = permissionId;
_userService = userService;
}
public override void OnActionExecuting(HttpActionContext actionContext)
{
base.OnActionExecuting(actionContext);
}
}
我在行动中设置了它:
public class HomeController : Controller
{
[PermissionChecker(1)]
public ActionResult Index()
{
return View();
}
}
但它不起作用!即使在PermissionChecker的构造函数中,代码也不会传入onActionExecuting。
答案 0 :(得分:5)
OnActionExecuting的签名不正确,应该有ActionExecutingContext:
提供ActionFilterAttribute类的ActionExecuting方法的上下文。
public override void OnActionExecuting(ActionExecutingContext filterContext){
base.OnActionExecuting(filterContext);
}