2017-09-26 1 views
0

이 문제는 나를 죽이고, 내가 시도한 것에 관계없이 해결할 수없는 것 같습니다. .Net WEB API에 HTTP 요청을 보내는 Angular 4 응용 프로그램이 있습니다. IIS Express에서 (Visual Studio 2013을 통해) Get, Put 및 Post 메소드를 포함하여 모든 것이 잘 작동했습니다. IIS 서버 나 로컬 IIS에서 Web API를 구성하자마자 Get 메서드가 작동하지만 Put 및 Post 작업이 중지되었습니다.405 메서드가 허용되지 않습니다 .Net Web Api

내 요청 :

 headers.append('Content-Type', 'application/json'); 
    return this.http.put('http://iisserver/dbServerMonitor/api/server/updateServer', this.serversService.getServer(index), {headers: headers}); 

WebConfig.Cs

public static void Register(HttpConfiguration config) 
    { 
     //Enable cors 
     var cors = new EnableCorsAttribute("*", "accept, accesstoken, autorization, cache-control, pragma, content-type, origin", "GET, PUT, POST, DELETE, OPTIONS"); 
     // Web API configuration and services 
     //var cors = new EnableCorsAttribute("*", "*", "*"); 
     //config.MessageHandlers.Add(new CorsHandler()); 

     config.EnableCors(cors); 
     // Web API routes 
     config.MapHttpAttributeRoutes(); 
     config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); 
     config.Routes.MapHttpRoute(
      name: "DefaultApi", 
      routeTemplate: "api/{controller}/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 
    } 

컨트롤러 :

[HttpPut] 
    [Route("updateServer")] 
    public HttpResponseMessage updateServer([FromBody] Server server) 
    { 
     ....code 

그리고 나는 또한 컨트롤러에 있습니다

[HttpOptions] 
    public HttpResponseMessage Options() 
    { 
     return new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; 
    } 

나는 웹 설정 XML 파일에서 CORS를 다루는 요청 코드에서 헤더를 모두 삭제하고 모든 것을 시도했지만 결국에는 CS 파일에서만 작동했다. 이 문제를 해결하는 방법에 관해 나는 전혀 모른다.

편집 : 인증을 제거한 후 이제는 내 로컬 IIS에 게시 및 Put을 성공적으로 호출 할 수있게되었습니다. 그러나 다른 IIS 서버 (동일한 도메인)에서 Put 및 Post 호출에 404가 표시됩니다. 도와주세요.

답변

0

IIS에서 모든 동사를 활성화해야합니다. IIS - 처리기 매핑 - ExtensionlessUrlHandler가 통합-4.0 - 요청 제한 ... - 동사 - 다음 동사 중 하나 또는 모든 동사

enter image description here

+0

그것은 이미 활성화되었다, 여전히 작동하지 않습니다. –

관련 문제