asp.net - Simple routing issue, optional not working -
i trying make lookup controller multiple actions. routing configuration is:
globalconfiguration.configuration.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional }); globalconfiguration.configuration.routes.maphttproute( name: "lookupsapi", routetemplate: "api/{controller}/{action}/{id}", defaults: new { id = routeparameter.optional });
my lookup controller
[httpget] public lookupslist getallstates() { } [httpget] public lookupslist getallsources() { //method }
when use following give nothing error stating "multiple actions found match request"
http://localhost:51042/api/lookups/getallstates or http://localhost:51042/api/lookups/getallsources
but when use
http://localhost:51042/api/lookups/getallstates/1 or http://localhost:51042/api/lookups/getallsources/1
it work fine.
how can set route work correctly.
thanks.
you have clash in routes think. example:
http://localhost:51042/api/lookups/getallstates
will match first route.
you should reverse ordering of routes:
update edsf:
config.routes.maphttproute( name: "lookupsapi", routetemplate: "api/{controller}/{action}/{id}", defaults: new {id = routeparameter.optional } ); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } );
additional helpful references:
Comments
Post a Comment