Search code examples
c#controllerhttpcontextasp.net-core-2.2

Get the Controller Name and Method Name in ASP.NET-Core 2.2 Controller


I know that in asp.net-core 2.2, I can get the action name as follows:

ControllerContext.ActionDescriptor.ActionName

but I am looking for a way to get the controller name of the current request/page in asp.net-core 2.2

I will appreciate any guide.

Thank you


Solution

  • You have access to controller name in the

    ControllerContext.ActionDescriptor.ControllerName
    

    property, given that the action descriptor is of ControllerActionDescriptor type

    Reference ControllerActionDescriptor.ControllerName