Asp.net web api 在ASP.NET WebApi路由中的{controller}之前添加自定义参数

Asp.net web api 在ASP.NET WebApi路由中的{controller}之前添加自定义参数,asp.net-web-api,Asp.net Web Api,我想为Owin WebApi创建一个路由模板,如下所示: cfg.Routes.MapHttpRoute( "API Default", "{myparam}/{controller}/{action}", new { id = RouteParameter.Optional }); 因为我已经定义了在选择控制器之前需要参数的控制器 我曾尝试删除该参数并将其设置为控制器上的RoutePrefixAttribute,但它不起作用 {controll

我想为Owin WebApi创建一个路由模板,如下所示:

cfg.Routes.MapHttpRoute(
            "API Default", "{myparam}/{controller}/{action}",
            new { id = RouteParameter.Optional });
因为我已经定义了在选择控制器之前需要参数的控制器

我曾尝试删除该参数并将其设置为控制器上的RoutePrefixAttribute,但它不起作用


{controller}必须是路由的第一个动态参数?

我将使用某种形式的基于属性的路由,根据{myparam}转到不同的控制器

第一控制器:

[路由(“param1/customer/{id}”)]
public IEnumerable GetOrdersByCustomer(int-id){…}

第二控制器:

[路由(“param2/customer/{id}”)]
public IEnumerable GetOrdersByCustomer(int-id){…}


更多信息可在此处找到:

删除RoutePrefix属性,并在动作路线属性中设置第一个参数dynamic,如下例所示:

[HttpGet, Route("{myparam}/books/{bookId:int:min(1)}")]
public HttpResponseMessage Get(string myparam, int bookId)
{
...
}

很抱歉,{myparam}在编译时是未知的,它是动态的(就像一个类别名称,但不是这样),