2012-12-04 2 views
2

요청을 일치 발견하지만, 그렇게 할 때 나는 다음과 같은 오류가 발생 해요 :ActionName을 사용한 MVC 라우팅; 여러 행동은 내 컨트롤러에 일부 사용자 정의 메소드를 추가하기 위해 노력하고있어

http://localhost/api/process/asdf 

여러 작업 요청을 일치 발견

WebApiConfig, 컨트롤러 또는 내 URL에 뭔가가 누락 되었습니까?

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) 
    { 
    } 

} 

답변

2

이 동음을 찾을 수있는 가장 좋은 방법은 routedebugger.dll를 사용하여 문제의 원인 경로 중 어느 찾을 수 있습니다 :

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 } 
     ); 
    } 
} 

가 여기 내 프로세스 컨트롤러 :

여기 내 WebApiConfig입니다.

관련 문제