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

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

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

    }

I can’t get the current request route. I want to create method access logic for users

David Specht
  • 7,784
  • 1
  • 22
  • 30
Temir
  • 1
  • 1

1 Answers1

1

One option would be to use the ActionFilterAttribute, then you'd have access to the ResultExecutingContext which has the route data you need. More information here

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

         base.OnResultExecuting(context);
     }
 }
Shoejep
  • 4,414
  • 4
  • 22
  • 26