Reputation: 15583
I have this custom action filter:
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);
}
}
and I set it in my action:
public class HomeController : Controller
{
[PermissionChecker(1)]
public ActionResult Index()
{
return View();
}
}
but it is not working! the code doesn't pass in onActionExecuting even in constructor of PermissionChecker.
Upvotes: 4
Views: 6144
Reputation: 20674
The signature of your OnActionExecuting is not correct, it should have ActionExecutingContext:
Provides the context for the ActionExecuting method of the ActionFilterAttribute class.
public override void OnActionExecuting(ActionExecutingContext filterContext){
base.OnActionExecuting(filterContext);
}
Upvotes: 6