如何使用机器IP地址与https一起运行/使用Kestrel托管dotnet核心应用程序(不使用IIS)

时间:2020-07-30 19:06:25

标签: .net-core kestrel-http-server

如何使用机器IP地址(https://192.168.1.102:5001而不是localhost(https:// localhost:5000)来使用Kestrel(不使用IIS)来托管/运行dotnet核心应用程序: < / p>

我正在使用以下配置

  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>();
                });

任何建议或指南将不胜感激,在此先感谢!

1 个答案:

答案 0 :(得分:0)

最后,我发现自己犯了一个愚蠢的错误。

我必须按照以下方式传递IP地址:

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