2

我正在尝试向我的控制器添加一些自定义方法,但是这样做时遇到以下错误:

http://localhost/api/process/asdf

找到多个与请求匹配的操作

我的 WebApiConfig、控制器或 url 中是否缺少某些内容?

这是我的 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)
    {
    }

}
4

1 回答 1

2

找到这种消歧的最佳方法是使用routedebugger.dll并找出导致问题的路径。

于 2012-12-04T17:05:13.140 回答