2
我想一些自定義的方法添加到我的控制器的請求,但這樣做的時候,所以我遇到了以下錯誤:未找到多個操作中發現匹配
http://localhost/api/process/asdf
多個動作匹配請求
我錯過了我的WebApiConfig,控制器或我的網址?
這裏是我的WebApiConfig:
public static class WebApiConfig {
public static void Register (HttpConfiguration config) {
config.Routes.MapHttpRoute(
name: "ControllerOnly",
routeTemplate: "api/{controller}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ControllerAndId",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ControllerAndActionGet",
routeTemplate: "api/{controller}/{action}",
defaults: new { action = "Get"}
);
config.Routes.MapHttpRoute(
name: "ControllerAndActionAndIdGet",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "Get", id = RouteParameter.Optional }
);
}
}
這裏是我的過程控制器:
public class ProcessController : BaseApiController
{
// GET api/process
public List<Process> Get()
{
return null;
}
[HttpGet]
[ActionName("asdf")]
public List<Process> asdf() {
return null;
}
[HttpGet]
[ActionName("fdsa")]
public List<Process> fdsa (int id) {
return null;
}
// GET api/process/5
public List<Process> Get (long id)
{
return null;
}
// POST api/process
public void Post ([FromBody]string value)
{
}
// PUT api/process/5
public void Put (int id, [FromBody]string value)
{
}
// DELETE api/process/5
public void Delete (int id)
{
}
}