Similar route mapping
- by Denis Agarev
I need to map to create controller what must response to two urls:
"http://localhost/api/controller?id=1" (where only id value can change)
"http://localhost/api/controller/anotherId/someconst" (where anotherId is the only one changing part)
i map it to such route:
routes.MapHttpRoute("Test", "api/{controller}/{id}/{someconst}", new { controller = "Test", someconst = RouteParameter.Optional });
And have to methods in my controller:
public void Get(int id) { ... }
public void Get(int anotherId, string someconst ) { ... }
It works...But it doesn't look nice...cause "string someconst" is not a param, it's just a const part of url. But if i remove "string someconst" param second url wouldn't work.
Is it possible to map one controller to two routes to resolve this urls to make it clear without fake param which is a const in fact?