I'm trying to get this to work:
[Route("api/Default")]
public class DefaultController : ApiController
{
[HttpGet, Route("{name}")]
public string Get(string name)
{
return $"Hello " + name;
}
}
by calling this http://localhost:55539/api/Default?name=rami
but not working, tried this also:http://localhost:55539/api/Default/Hello?name=rami
, Also this not working: http://localhost:55539/api/Default/Hello/rami
Make sure attribute routing is enabled in WebApiConfig.cs
ApiController actions can have multiple routes assigned to them.
There is also the option of making the parameter optional, which then allow you to call the URL with out the inline parameter and let the routing table use the query string similar to how it is done in convention-based routing.
In Web API first route template matching happens and then the action selection process.
Your C# should be like this:
Now call should be like this: