0
    [CheckAccessMethod(RouteData.Values["action"].ToString())]
    [HttpGet]
    public IActionResult Get(){...}

    class CheckAccessMethodAttribute : Attribute
    {
         string MethodName { get; set; }

        public  CheckAccessMethodAttribute(string methodName)
        {
            MethodName = methodName;
        }

    }

我无法获得当前的请求路线。我想为用户创建方法访问逻辑

4

1 回答 1

1

一种选择是使用 ActionFilterAttribute,然后您就可以访问具有所需路由数据的 ResultExecutingContext。更多信息在这里

public class MyActionFilterAttribute : ActionFilterAttribute
{
     public override void OnResultExecuting(ResultExecutingContext context)
     {
         var action = context.RouteData.Values["action"];
         //do something with action here

         base.OnResultExecuting(context);
     }
 }
于 2020-02-11T15:19:20.657 回答