0

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?

1 Answer 1

1

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{},
                 );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.