문제

For an already agreed (between customer and us) URL like,

http://URL/companyapi/orders/100191/sendrequest?for=customer123&card=123451

I am defining a route map like this:

public static void Register(HttpConfiguration config)
{
   config.Routes.MapRoute(
                 name: "Service",
                 routeTemplate: "companyapi/orders/{orderId}/{controller},
                 default: new{},
                 );
}

For retrieving other query string parameters, I think it is enough if I do this:

public void Get(string for, int card)
{
        // How to retrieve the orderId ?
}

1. How to retrieve the orderId because it comes before controller portion in the route Template?

2. Is it perfectly normal to leave the default part of the MapRoute function?

도움이 되었습니까?

해결책

Please add orderId parameter to Get Method.

public void Get(int orderId, string for, int card)
{
        // How to retrieve the orderId ?
}

and change RouteConfig.cs file

public static void Register(HttpConfiguration config)
{
   config.Routes.MapRoute(
                 name: "Service",
                 routeTemplate: "companyapi/orders/{orderId}/{controller},
                 default: new{},
                 );
}

to

public static void Register(HttpConfiguration config)
{
   config.Routes.MapRoute(
                 name: "Service",
                 routeTemplate: "companyapi/orders/{controller},
                 default: new{},
                 );
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top