C# 在Web API中检索查询字符串
对于已经商定的(客户和我们之间)URL,如C# 在Web API中检索查询字符串,c#,asp.net,asp.net-mvc,asp.net-mvc-routing,asp.net-web-api,C#,Asp.net,Asp.net Mvc,Asp.net Mvc Routing,Asp.net Web Api,对于已经商定的(客户和我们之间)URL,如 http://URL/companyapi/orders/100191/sendrequest?for=customer123&card=123451 我定义的路线图如下: public static void Register(HttpConfiguration config) { config.Routes.MapRoute( name: "Service", ro
http://URL/companyapi/orders/100191/sendrequest?for=customer123&card=123451
我定义的路线图如下:
public static void Register(HttpConfiguration config)
{
config.Routes.MapRoute(
name: "Service",
routeTemplate: "companyapi/orders/{orderId}/{controller},
default: new{},
);
}
对于检索其他查询字符串参数,我认为这样做就足够了:
public void Get(string for, int card)
{
// How to retrieve the orderId ?
}
1。如何检索orderId
,因为它位于路由模板中的controller
部分之前?
2。保留
MapRoute
函数的默认部分是否完全正常?请添加orderId参数以获取方法
public void Get(int orderId, string for, int card)
{
// How to retrieve the orderId ?
}
并更改RouteConfig.cs文件
public static void Register(HttpConfiguration config)
{
config.Routes.MapRoute(
name: "Service",
routeTemplate: "companyapi/orders/{orderId}/{controller},
default: new{},
);
}
到
public static void Register(HttpConfiguration config)
{
config.Routes.MapRoute(
name: "Service",
routeTemplate: "companyapi/orders/{controller},
default: new{},
);
}