Given the uri…
http://localhost:5613/api/user/1/HasCompletedInitialScreen
I have the following route configured…
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "ApiUserHasCompletedInitialScreen",
routeTemplate: "api/user/{id}/{hascompletedinitialscreen}");
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
and the controller action…
[HttpGet]
[ActionName("HasCompletedInitialScreen")]
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!!
UPDATE
Based on the accepted answer, I modified my api route definition to the following. Hope this helps someone else…
config.Routes.MapHttpRoute(
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:
Where
SomethingControlleris your controller containing theHasCompletedInitialScreenaction.On a side note, you don’t need to declare
ActionNameattribute if its name is the same as your action method name.