Question

I'm new with attribute routing with aspnet web api.

public class UsersController : ApiController
{
    [GET("users/me/brands/{id}")]
    public IEnumerable<Brand> GetBrands(long id)
    {
        return _repository.FindByUser(id);
    }
}

but I could not reach this action. I've tried so many ways:

  1. http://example.com/api/users/brands/4
  2. http://example.com/api/users/brands?id=4
  3. http://example.com/users/brands?id=4
  4. http://example.com/users/brands/4

PS: I also mapped as [GET("api/users/me/brands/{id}")]

What I'm missing?

Was it helpful?

Solution

There is a bug in the web api routing with MVC 4 and 4.5

A full explanation and work around can be found

MVC 4.5 Web API Routing not working?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top