自托管 Web 服务无加载
Self-Hosted Web service no loading
我只是想打开 运行 我的团队项目之一,它是配置为自托管的 .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
- 我从 Telerik 安装了 Fiddler,这有点帮助,因此它不再抛出 404
-但是,它现在抛出一个不同的错误,如下所示:
[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
我不知道还能做什么。有什么建议吗?
尝试使用
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
。
例如下面的控制器
[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);
}
}
以上主机配置应分别匹配以下网址
http://localhost:3434/
http://localhost:3434/echo/stack-overflow
我只是想打开 运行 我的团队项目之一,它是配置为自托管的 .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
- 我从 Telerik 安装了 Fiddler,这有点帮助,因此它不再抛出 404 -但是,它现在抛出一个不同的错误,如下所示:
[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
我不知道还能做什么。有什么建议吗?
尝试使用
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
orhttps://*:5001
). The protocol (http://
orhttps://
) 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
。
例如下面的控制器
[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);
}
}
以上主机配置应分别匹配以下网址
http://localhost:3434/
http://localhost:3434/echo/stack-overflow