2017-04-04 13 views
0

저는 팀 프로젝트 중 하나를 열고 실행하려고하고 있으며 자체 호스팅되도록 구성된 .NET Web API 프로젝트입니다. 되는 구성은 다음과 같습니다 :자체 호스팅 웹 서비스가로드되지 않습니다.

var host = new WebHostBuilder() 
       .UseContentRoot(Directory.GetCurrentDirectory()) 
       .UseKestrel() 
       .UseStartup<Startup>() 
       .UseUrls("http://0.0.0.0:3434") 
       .Build(); 

      host.Run(); 
  • 가 실행되면 성공적으로 서비스가 "http://0.0.0.0:3434"에서 수신하는 것을 말한다 콘솔을 시작합니다. 여태까지는 그런대로 잘됐다. 실제로 해당 위치로 이동하려고 할 때
  • 지금, 그것은 아무것도로드하고 날 404
  • 는 더 이상 를 (404)가 발생하지 않도록 내가 조금 도움이 Telerik에서 피들러를 설치 - 그러나이 발생하지 않습니다

[Fiddler] The connection to '0.0.0.0' failed. Error: AddressNotAvailable (0x2741). System.Net.Sockets.SocketException The requested address is not valid in its context 0.0.0.0:3434

내가 할 다른 무엇 확실하지 않다 : 그것은 지금처럼 아래 보이는 다른 오류가 발생합니다. 어떤 제안?

+1

'0.0.0.0'을 다음 URL과 일치해야 위의 호스트 구성을 사용하여 다음 컨트롤러

[Route("")] public class RootController : Controller { [HttpGet] //Matches GET/ public IActionResult Get() { return Ok("hello world"); } [HttpGet("echo/{value}] //Matches GET /echo/anything-you-put-here public IActionResult GetEcho(string value) { return Ok(value); } } 

은 당신의 시스템의 모든 IP에 바인딩되는 것을 의미 , 당신은 여전히 ​​물리적 주소를 통해 연결을 설정해야합니다. 'http : //127.0.0.1 : 3434'와'http : // 192.168.0.11' <-이 당신의 lan 주소가 되길 시도하십시오. –

답변

1

에 한번 사용

var host = new WebHostBuilder() 
      .UseContentRoot(Directory.GetCurrentDirectory()) 
      .UseKestrel() 
      .UseStartup<Startup>() 
      .UseUrls("http://*:3434") 
      .Build(); 

host.Run(); 

원본 문서 Introduction to hosting in ASP.NET Core

Server URLs string

Key: urls . Set to a semicolon (;) separated list of URL prefixes to which the server should respond. For example, http://localhost:123 . The domain/host name can be replaced with " * " to indicate the server should listen to requests on any IP address or host using the specified port and protocol (for example, http://*:5000 or https://*:5001). The protocol (http:// or https://) must be included with each URL. The prefixes are interpreted by the configured server; supported formats will vary between servers.

new WebHostBuilder() 
    .UseUrls("http://*:5000;http://localhost:5001;https://hostname:5002") 

호스트가하고 지금 실행하는 컨트롤러가 올바른 경로가 구성되어 있는지 확인하고의 문제와 그 권리되면 URL이 호출되고, 그렇지 않으면 404 Not Found이 리턴됩니다. 예를 들어

각각

http://localhost:3434/ 

http://localhost:3434/echo/stack-overflow 
+0

글쎄,'* 또는 실제로 localhost로 변경하면 404를 던지기 시작한다. 무엇을 해야할지 잘 모르겠다. – TeaLeave

+1

@ CoffeeBean은 이제 컨트롤러에 올바른 경로가 구성되어 있고 올바른 권한을 가지고 있는지 확인하는 문제가있다. URL. 루트 URL을 처리하는 컨트롤러가 있습니까? – Nkosi

+0

오케이 그래서 문제를 발견했습니다. 그것은 내 편이 조금 바보 같았다. 루트 디렉토리에로드 할 인덱스와 같은 기본 파일이 없으므로 URL/swagger.html을 명시 적으로 탐색해야만 모든 것이 올바르게 설정되었습니다. – TeaLeave