Hi I have this REST services
I succeed configuring the route with this mapping:
config.Routes.MapHttpRoute(
name: "ActionApiWithId",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
And this controllers
public class AdminController : ApiController
{
// GET api/admin/delegatedusers
[ActionName("delegatedusers")]
public IEnumerable<x> Get()
{
}
// GET api/delegatedusers/<userid>
[ActionName("delegatedusers")]
public x Get(String id)
{
}
}
public class DelegatedUsersController : ApiController
{
public x Get()
{
}
}
The problem is that I add a new method that is not properly resolved. The method is
Using this mapping and controller
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
public class EnrollRequestController : ApiController
{
/// DELETE api/enrollrequest/<id>
public void Delete(String id)
{
}
}
If I put the DefaultApi routMapping on top of the WebApiConfig file then this new method is resolved but GET admin/delegateduser is not. So it looks like this two methods conflict on URL resolutions.
How would be the right way to map the methods? May be everything should be more simple and I got too complicated....
Any help is wellcomed.
Thanks in advance.
Finally I found the solution,
The conflict was that DELETE enrollrequest/ and GET admin/delegateduser both fit with the rules
{controller}/id
{controller}/action
I solve that adding a constraint this way:
config.Routes.MapHttpRoute(
name: "ActionApiWithId",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { action = "delegatedusers" }
);
Now the call DELETE enrollrequest/ does not fit the route because the don't fullfill the constraint.