-1

我有 Windows Server 2016 数据中心 x64、.NET Core SDK 5.0 预览版、Microsoft SQL Server 2019

在此处输入图像描述

在服务器上:https://localhost:5001/publisher/一切正常

在服务器上https://127.0.0.1:5001/publisher/一切正常

在服务器上:防火墙打开端口 5000-6000 出站

从我的电脑(或世界上的任何电脑)https://45.118.145.72:5011/publisher/all not ok

在此处输入图像描述

如何从公共互联网访问https://45.118.145.72:5011/publisher/all ?

在此处输入图像描述

4

3 回答 3

1

Asp.NET 核心应用程序使用默认设置绑定到“localhost”网络接口。其他主机无法使用此网络接口。

UseUrls()您可以在主机设置期间修改它。

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
            webBuilder.UseUrls("http://0.0.0.0:5001");
        });

例子:

webBuilder.UseUrls("http://127.0.0.1:5001"); // only from localhost
webBuilder.UseUrls("http://localhost:5001"); // only from localhost
webBuilder.UseUrls("http://0.0.0.0:5001");   // allow all hosts

文档:https ://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-in-aspnet-core-apps

于 2020-07-21T09:51:16.077 回答
1

改成0.0.0.0

文件launchSettings.json

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:51632",
      "sslPort": 44360
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "publisher/all",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "acc_ai": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "publisher/all",
      "applicationUrl": "https://0.0.0.0:5001;http://0.0.0.0:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

从内部服务器转到 https://localhost:5001/news/all。

从公共互联网到 https://public_ip:5001/news/all。

于 2020-07-21T10:12:30.127 回答
1

您还需要在我们的防火墙/路由器上转发端口 5001。

于 2020-07-31T14:00:17.440 回答