2017-09-09 9 views
0

웹 API 프로그램을 작성했습니다. 로컬 Windows 서버에서 실행되고 다른 로컬 Windows 서버에서 테스트되었습니다. 내가 Plesk를 호스팅에 업로드 할 때, 그것은 작동하지 않습니다와 나는이 오류가 발생했습니다 :plesk에서 웹 API 프로그램을 실행하는 방법

404 - File or directory not found.

나는

<httpProtocol> 
    <customHeaders> 
    <add name="Access-Control-Allow-Origin" value="*" /> 
    </customHeaders> 
</httpProtocol> 

내 샘플 API 주소는 Here이다 Web.config의에서 하나의 특정 항목을 설정합니다.

특정 설정을 지정해야합니까?

답변

0

내가 ASP.NET 웹 API에 간 원산지 요청을 사용한다 2. 내가 Here

이 주제는 내가

Install-Package Microsoft.AspNet.WebApi.Cors

을 설치해야합니다 읽어 파일을 엽니 후 App_Start/WebApiConfig.cs . WebApiConfig.Register 메서드에 다음 코드를 추가합니다.

using System.Web.Http; 
namespace WebService 
{ 
    public static class WebApiConfig 
    { 
     public static void Register(HttpConfiguration config) 
     { 
      // New code ((((((important this (config.EnableCors) item)))))) 
      config.EnableCors(); 

      config.Routes.MapHttpRoute(
       name: "DefaultApi", 
       routeTemplate: "api/{controller}/{id}", 
       defaults: new { id = RouteParameter.Optional } 
      ); 
     } 
    } 
} 

는 다음 후 TestController 클래스에 [EnableCors] 속성을 추가 :

using System.Net.Http; 
    using System.Web.Http; 
//((((((important this (using System.Web.Http.Cors) item)))))) 
    using System.Web.Http.Cors; 

    namespace WebService.Controllers 
    { 
//((((((important this (EnableCors) item)))))) 
     [EnableCors(origins: "http://mywebclient.azurewebsites.net", headers: "*", methods: "*")] 
     public class TestController : ApiController 
     { 
      // Controller methods not shown... 
     } 
    } 

이 항목 후에는 가상 디렉터리를 확인해야하고 패주 폴더 또는 하위 도메인에 업로드해야합니다.