Web Api route returns a 404

Given the uri...


I have the following route configured...

public static class WebApiConfig
    public static void Register(HttpConfiguration config)
            name: "ApiUserHasCompletedInitialScreen",
            routeTemplate: "api/user/{id}/{hascompletedinitialscreen}");

            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }

and the controller action...

public HttpResponseMessage HasCompletedInitialScreen(int id)
    var response = Request.CreateResponse<bool>(HttpStatusCode.Created, true);
    response.Headers.Location = GetLocation(id);
    return response;

However, I get a 404. How do I fix my route configuration and/or controller action to make this work?

Many thanks!!


Based on the accepted answer, I modified my api route definition to the following. Hope this helps someone else...

            name: "QueryApi",
            routeTemplate: "api/{controller}/{id}/{action}");


I'm not sure what you are trying to do but, if you want to be able to call


Your route needs to be like this:

                name: "ApiUserHasCompletedInitialScreen",
                routeTemplate: "api/user/{id}/{action}",
                defaults: new { controller = "Something" }

Where SomethingController is your controller containing the HasCompletedInitialScreen action.

On a side note, you don't need to declare ActionName attribute if its name is the same as your action method name.

Need Your Help

Worklight Adapter Deployment


I am new to IBM Worklight, now started using Adapters and I am able to Run the application from Eclipse IDE but I need some help to Execute the same app in a device (iPAD/tablet).

MonoTouch - get list of connected outlets

c# ios mono monotouch viewdidunload

I am working on a large iOS application and am at the phase where I'm doing some cleanup/performance tuning.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.