鉴于 uri...
http://localhost:5613/api/user/1/HasCompletedInitialScreen
我配置了以下路线...
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 }
);
}
}
和控制器动作...
[HttpGet]
[ActionName("HasCompletedInitialScreen")]
public HttpResponseMessage HasCompletedInitialScreen(int id)
{
var response = Request.CreateResponse<bool>(HttpStatusCode.Created, true);
response.Headers.Location = GetLocation(id);
return response;
}
但是,我收到 404。如何修复我的路由配置和/或控制器操作以使其正常工作?
非常感谢!!
更新
根据接受的答案,我将我的 api 路由定义修改为以下内容。希望这对其他人有帮助...
config.Routes.MapHttpRoute(
name: "QueryApi",
routeTemplate: "api/{controller}/{id}/{action}");