c# - MapRoutes not working -
i can't see going wrong here. have more specific route on top returns error 404 - not found.
doing /api/playernames/competitions works /api/playernames/teams/competitionid/81bbd23d-54a2-4204-a771-85c48555a992 not. doing wrong?
routes.maproute("playernamesdbteams", "playernames/teams/competitionid/{competitionid}", new { controller = "playernames", action = "teams", competitionid = "" }); routes.maproute("default", "{controller}/{action}/{id}", new { controller = "playernames", action = "competitions" }); public class playernamescontroller : apicontroller { [httpget] public list<competition> competitions() { using (var service = new aggregatorclient()) { return service.getcompetitions(); } } [httpget] public list<team> teams(string competitionid) { using (var service = new aggregatorclient()) { return service.getteams(competitionid); } } } making request /api/playernames/teams?competitionid=xxxxxx work.
you appear using mvc routing; if using apicontrollers should use webapiconfig define routes.
open webapiconfig.cs in app_start folder , define routes follows:
config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{action}/{id}", defaults: new { id = routeparameter.optional } ); config.routes.maphttproute( name: "playernamesdbteams", routetemplate: "api/{controller}/{action}/competitionid/{competitionid}", defaults: new { competitionid = "" } );
Comments
Post a Comment