我的Web api项目具有以下路线:
config.Routes.MapHttpRoute(
name: "Default_Api",
routeTemplate: "api/v{version:apiVersion}/{lang}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
然后我需要将{lang}
参数放入Application_BeginRequest
:
var httpContext = HttpContext.Current;
RouteData currentRouteData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));
string lang = currentRouteData.Values["lang"] as string;
,但始终返回null 我该怎么做?
答案 0 :(得分:0)
您可以使用HttpContext.Current.Request.RequestContext.RouteData