How to get the current ASP.NET core controller method name inside the controller using Reflection or another accurate method

后端 未结 5 1565
深忆病人
深忆病人 2021-02-12 17:40

I want to get the current method name of my ASP.NET Core controller

I have tried getting the method name through reflection:

    [HttpGet]
         


        
5条回答
  •  太阳男子
    2021-02-12 18:20

    You can use the fact that it is not just any method but a controller and use ActionContext.ActionDescriptor.Name property to get the action name

    UPDATE: (thanks to Jim Aho)

    Recent versions work with -

    ControllerContext.ActionDescriptor.ActionName
    

提交回复
热议问题