如何使用带有 https 的机器 ip 地址到 运行 / 使用 Kestrel 的主机 dotnet 核心应用程序(没有 IIS)

How to use machine ip address with https to run / host dotnet core application using Kestrel(Without IIS)

如何使用机器 IP 地址 (https://192.168.1.102:5001) 而不是本地主机 (https://localhost:5000) 到 host/run 使用 Kestrel 的 dotnet 核心应用程序(无 IIS) :

我正在使用以下配置

  Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.ConfigureKestrel(serverOptions =>
        {
            serverOptions.Listen(IPAddress.Loopback, 5000);
            serverOptions.Listen(IPAddress.Loopback, 5001, 
                listenOptions =>
                {
                    listenOptions.UseHttps("cert.pfx", 
                        "123");
                });
        })
        .UseStartup<Startup>();
    });

我知道我们可以使用 .UseUrls("http://192.168.0.101:5001") 如下,但这不适用于 https

 Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.
                    UseKestrel()
            .UseUrls("http://192.168.0.101:5001")
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration().UseStartup<Startup>();
                });

如有任何建议或指导,我们将不胜感激,在此先感谢!

终于,我发现了我犯的愚蠢错误。

我必须按如下方式传递 ip 地址:

serverOptions.Listen(IPAddress.Parse("192.168.0.101"), 5001, ....