asp.net web api - How to use the same route with different parameter types? -
i have api controller 2 different actions take different parameter types.
// get: users/sample%40email.com [route("users/{emailaddress}")] public ihttpactionresult getuser(string emailaddress) // get: users/1d8f6b90-9bd9-4cdd-babb-372242ad9960 [route("users/{reference}")] public ihttpactionresult getuserbyreference(guid reference)
problem multiple actions found matching when make request either. looking @ other answers thought needed setup routes in webapiconfig so...
config.routes.maphttproute( name: "apiemail", routetemplate: "api/{controller}/{action}/{email}" ); config.routes.maphttproute( name: "apireference", routetemplate: "api/{controller}/{action}/{reference}" );
what need each action called based on parameter type pass in?
i'm new web.api additional explanation text appreciated.
you below method declaration attribute routing enabled: //declare method guid 1st
// get: users/1d8f6b90-9bd9-4cdd-babb-372242ad9960 [route("users/{reference:guid}")] public ihttpactionresult getuserbyreference(guid reference)
and declare other method below
// get: users/sample%40email.com [route("users/{emailaddress}")] public ihttpactionresult getuser(string emailaddress)
please let me know, work ?
Comments
Post a Comment