2016-07-15 3 views
0
내가 ASP.Net 웹 API의 구조 아래에 만들려고하고

2ASP.NET 웹 API 광고 2 라우팅

https://<host>/api/webhooks/incoming/custom 
나는 컨트롤러 webhooks을 만들어 webhooks를 탐색 할 수 있습니다하지만 어떻게 내가 그 아래 다른 두를 만들 수 있습니다

?

여기에 대한 의견이 있으십니까?

답변

2

속성 라우팅에서이 작업을 수행 할 수 있습니다.

컨트롤러에서 RoutePrefix를 컨트롤러에 추가 한 다음 메서드에 직접 추가 경로를 지정할 수 있습니다. 그런 다음 컨트롤러 내부의 모든 메소드 경로는 api/webhooks/incoming으로 시작합니다. GetStarted()를 호출하는 노선 api/webhooks/incoming/custom

[RoutePrefix("api/webhooks/incoming")] 
    public class StartUpController : ApiController 
    { 
     [HttpGet] 
     [Route("custom")] 
     [AllowAnonymous] 
     public IHttpActionResult GetStarted() 
     { 
      return Ok(); 
     } 
    } 

될 것입니다 아니면 방법에 직접적으로 전체 경로를 지정할 수 있습니다. 노선은 또한 당신은 그것을 here

에 대한 자세한 내용을보실 수 있습니다 api/webhooks/incoming/custom

public class StartUpController : ApiController 
    { 
     [HttpGet] 
     [Route("api/webhooks/incoming/custom")] 
     [AllowAnonymous] 
     public IHttpActionResult GetStarted() 
     { 
      return Ok(); 
     } 
    } 

될 것입니다