2017-01-16 2 views
1

로컬로 잘 작동하는 API가 있고 라이브 환경으로 이동할 때 그렇지 않습니다.WebAPI 컨트롤러가 작동하지 않는 경우

주요 POST의 영향을받는 컨트롤러의 반환에 대한 조치 : 테스트 GET 조치와

NotFound 

내가 다시 얻을 :

"Message": "No HTTP resource was found that matches the request URI 

을 이상하게도, 나는 동일한 테스트 작업으로 함께 testController을 업로드 할 때 주 컨트롤러에서 사용되는 API에서 적절한 응답을받습니다. 웹 설정

public class DeviceController : ApiController 
{ 

    [AllowAnonymous] 
    [HttpGet] 
    public HttpResponseMessage helloWorld() // This returns: "No HTTP resource was found that matches the request URI 'http://api.mySite.com/api/Device/helloWorld'." 
    { 
     return Request.CreateResponse(HttpStatusCode.OK, "HelloWorld!"); 
    } 

    [AllowAnonymous] 
    [HttpPost] 
    public HttpResponseMessage Login([FromBody] LoginObject loginObject) // This returns: "NotFound" 
    { 
     ... 
    } 

} 여기

됩니다 :

public static class WebApiConfig 
{ 
    public static void Register(HttpConfiguration config) 
    { 
     config.MapHttpAttributeRoutes(); 

     config.Routes.MapHttpRoute(

      name: "API Default", 
      routeTemplate: "api/{controller}/{action}/{id}", 
      defaults: new { id = RouteParameter.Optional } 

     ); 
    } 
} 
+0

그래서'HTTP에 의해 같은 경로의 선언 권리? – Marusyk

+0

네, 실제로 "HelloWorld!"를 얻습니다. 뒤로. 이것은 매우 이상하게 보입니다 ... 라우팅 문제가되어야합니까? – Ryan

+0

흠 ... 확인해 볼 수 있습니다. 경로 속성'[Route ("api/Device/helloWorld")]' – Marusyk

답변

1

public class TestController : ApiController 
{ 

    [AllowAnonymous] 
    [HttpGet] 
    public HttpResponseMessage helloWorld() 
    { 
     return Request.CreateResponse(HttpStatusCode.OK, "HelloWorld!"); 
    } 
} 

컨트롤러 작동하지 않습니다

잘 작동 테스트입니다

노골적인 추가 시도 // api.mySite.com/API/테스트/helloWorld` 작동 : LY는 acrion

[Route("api/Device/helloWorld")] 
[AllowAnonymous] 
[HttpGet] 
public HttpResponseMessage helloWorld() 

또는

[RoutePrefix("api/Device")] 
public class DeviceController : ApiController 

다음

[Route("helloWorld")] 
[AllowAnonymous] 
[HttpGet] 
public HttpResponseMessage helloWorld() 
+0

경로를 명시 적으로 선언하여이 문제를 해결했습니다. 감사합니다. – Ryan