0
votes

Say I have those methods in a controller:

Get() 

[HttpGet]
FindSomeone()

I have a default route, and a route with actions: routeTemplate: "api/{controller}/{action}".

Works fine when I call /mycontroller/FindSomeone, but fails with multiple matching routes error when I call GET /mycontroller/.

Is there a way to make default route to match Get() method only, and skip the FindSomeone() method?

2
why don't you call /mycontroller/get - cuongle

2 Answers

0
votes

Declare the default Get action for all controllers in the main routing

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional, action ="Get" }
    );
0
votes

AttributeRouting migh work better for you in this scenario. It should be as simple as decorating the two methods with a Get Attribute,

[RoutePrefix("mycontroller")
public class MyController 
{
  [GET("")]
  Get() 

  [GET("FindSomeone")]
  FindSomeone()
}

That will make those methods available as mycontroller and mycontroller/FindSomeone.