gpt4 book ai didi

c# - ActionFilterAttribute 未调用

转载 作者:行者123 更新时间:2023-12-02 17:58:25 24 4
gpt4 key购买 nike

我有这个自定义操作过滤器:

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。

最佳答案

你的OnActionExecuting的签名不正确,它应该有ActionExecutingContext :

为 ActionFilterAttribute 类的 ActionExecuting 方法提供上下文。

public override void OnActionExecuting(ActionExecutingContext filterContext){
base.OnActionExecuting(filterContext);
}

关于c# - ActionFilterAttribute 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13472822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com