使用 ASP.NET CORE 编写 RESTful API 服务默认监听的是 localhost,我们可以通过修改 appsettings.json 来让我们的服务监听服务器上指定的或者所有的IP。比如加入"urls": "http://0.0.0.0:5000"到 appsetings.json来在服务器所有的ip上通过端口5000来监听服务请求。
实例如下:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"urls": "http://0.0.0.0:5000",
"AllowedHosts": "*"
}