Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I cannot figure out for the life of me why my attribute routing isn't working.

Here is my setup:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Attribute routing
        config.MapHttpAttributeRoutes();

        // Convention-based routing
        config.Routes.MapHttpRoute(
            name: "API Default",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

    }
}

Here is my controller with my routing attributes:

[Route("api/v1.0/orders")]
public class OrdersV1Controller
{

    [APIAuthentication(RequireAuthentication = true)]
    [HttpGet]
    [Route("{id:int}")]
    public GetOrderResponse GetOrder(int id)
    { 
      .....
    }
}

Here is my global asax file:

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Populate;
    }
}

Here is the URL i'm testing which is returning a 404 not found:

http://localhost:60105/api/v1.0/orders/111111

share|improve this question
1  
have you considered public class OrdersV1Controller : ApiController –  Jonesy May 13 at 13:20
    
Wow i can't believe i missed that in all the examples... argh... that did it man.. add it as an answer so i can give you credit –  99823 May 13 at 13:21
    
haha glad it fixed it –  Jonesy May 13 at 13:22
    
hey - you and me both, i've been working on this for 2 days... lmao.. i feel so stupid.. haha thanks again man –  99823 May 13 at 13:22

1 Answer 1

up vote 3 down vote accepted

your controller needs to be an API Controller :

public class OrdersV1Controller : ApiController
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.