Get controller name

前端 未结 1 606
半阙折子戏
半阙折子戏 2020-12-29 12:54

In WebApiConfig.cs i have the following

public static void Register(HttpConfiguration config)
{

   config.MapHttpAttributeRoutes(); 

   config.Services.Rep         


        
相关标签:
1条回答
  • 2020-12-29 13:38

    As confirmed by @KiranChalla there is no simpler way then the one I've already implemented, except the minor suggestion to use GetSubRoutes()

    var attributedRoutesData = request.GetRouteData().GetSubRoutes();
    var subRouteData = attributedRoutesData.FirstOrDefault();
    
    var actions = (ReflectedHttpActionDescriptor[])subRouteData.Route.DataTokens["actions"];
    var controllerName = actions[0].ControllerDescriptor.ControllerName;
    
    0 讨论(0)
提交回复
热议问题