Why is it so hard to get route values outside controller context?

后端 未结 2 1377
挽巷
挽巷 2021-01-21 20:18

I don\'t understand what\'s the deal behind this, why is it so easy to get route values inside Request of controller but nearly impossible to do the same thing on <

2条回答
  •  Happy的楠姐
    2021-01-21 20:48

    Try the code below to get the route data:

    var routeValues = Request.GetRouteData().Values["MS_SubRoutes"];
    

    Note:

    The type of Request is System.Net.Http.HttpRequestMessage. It is a property of class System.Web.Http.ApiController, or you can get it from eleswhere.

    GetRouteData is an extension method in class System.Net.Http.HttpRequestMessageExtensions.

提交回复
热议问题