Reputation: 4768
I have a very basic WebApi Controller as shown below, which uses attribute routing.
public class ValueController : ApiController
{
//This route returns a 404
[Route("api/v1/values")]
public Value GetValue()
{
return new Value() { Name = "api/v1/values" };
}
//this route works fine
[Route("api/v1/values/{valueId}")]
public Value GetValueById(int valueId)
{
return new Value() { Name = "api/v1/values/{valueId}" };
}
//this route works fine
[Route("api/v1/values/{valueId}/more")]
public Value GetChildOfValue()
{
return new Value() { Name = "api/v1/values/{valueId}/more" };
}
}
For some reason the first route returns a 404. The other two both work as expected.
Attribute routing is turned on in WebApiConfig.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
}
}
Any ideas on why the first route does not work???
Upvotes: 1
Views: 201
Reputation: 9043
Here is how I called them and all worked correctly, maybe you are requesting /api/v1/value not value**s**
http://localhost:62138/api/v1/values
http://localhost:62138/api/v1/values/22
http://localhost:62138/api/v1/values/22/more
Upvotes: 1