.NET Core 从外部访问站点?

.NET Core Access Site Externally?

当我在调试模式下使用 Kestrel 在 VS 2019 中启动我的 .NET Core 应用程序时,我只能以 https:// localhost:5001 访问。当我尝试用我的计算机的 fqdn 替换 localhost 时,我得到 "Site cannot be reached"。所以实际上应该是计算机和域名 https:// win7.int.com:5001。我想这样做,以便我可以从另一台机器访问该站点。如果它不能以这种方式在我自己的机器上运行,我怀疑它是否可以在另一台机器上运行。现在理想情况下,我会在这个主页下有几个应用程序(如 app1、app2 等)。 URL 将是 https:// win7.int.com/app1:5001https:// win7.int.com/app2:5001 等等。

对不起,我有 grails 背景,当应用程序在 localhost 上启动时,我只需将 localhost 替换为我的计算机名称即可,它可以正常工作。我需要做什么才能在不通过 IIS 的情况下在 .NET Core 中完成这项工作?想使用 Kestrel。

默认情况下,Kestrel 仅绑定到 http://localhost:5000 and https://localhost:5001

如果您想更改此设置,您可以使用 UseUrls 方法配置 IP 地址或主机地址以及服务器应侦听请求的端口和协议:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).UseKestrel().UseUrls("http://*:5000;https://*:5001")
.UseStartup<Startup>();