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

Determining Word Frequency of Specific Terms

linux text analysis frequency word-frequency

I'm a non-computer science student doing a history thesis that involves determining the frequency of specific terms in a number of texts and then plotting these frequencies over time to determine c...

javascript: how to access static properties

javascript properties static

I want to access a static property using an instance. Something like this

Comparing output to a list/array

python arrays list mx-record

I consider myself a very beginner at python(and programming in general!), but I am working though "learn python the hard way" by Zed A Shaw and slowing picking things up.

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.