Reputation: 1321
I know you can alter the default behaviour of routing in Web API like this:
routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
But can you
routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}?verb={action}",
defaults: new { action = RouteParameter.Optional }
);
Edit: The following route templates gives the following errors:
"api/{controller}?verb={action}"
throws a YSOD becaus of the ?-character
"api/{controller}%3Fverb={action}"
Throws the following
Multiple actions were found that match the request: GetRecord on type RouteConfigMedGet.Controllers.TestController ListRecords on type RouteConfigMedGet.Controllers.TestController
Upvotes: 0
Views: 782
Reputation: 1299
As I know you cannot write routes with query string params.
If you want to make sure that your controller's action will handle requests only with specific query params you may create custom route constraint where you will check if required param is present and add it as constraint to your route.
In general solution to use query params to devide different actions is realy strange. I copied nice explanation from this thread:
Routes are meant to delineate one resource from another, whereas as you stated, QueryString parameters are meant for Presentation logic*. Therefore you cannot expect a URL pointing to a resource to go to a different resource if the same URL is used, but with querystring parameters. This is not a failing of MVC, rather I don't believe you're using Querystrings correctly.
by George Stocker.
Upvotes: 1