【问题标题】:How to use machine ip address with https to run / host dotnet core application using Kestrel(Without IIS)如何使用带有 https 的机器 ip 地址来运行/使用 Kestrel 托管 dotnet 核心应用程序(不带 IIS)
【发布时间】:2023-03-23 11:47:01
【问题描述】:

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

我正在使用以下配置

  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。尝试使用这个:转到 cmd => ipconfig => 以太网适配器以太网 => IPv4 地址
  • 嗯 ????,其实这是正确的 IPv4 地址。

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


【解决方案1】:

最后,我发现了我犯的愚蠢错误。

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

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

【讨论】:

    猜你喜欢
    • 2022-12-22
    • 2018-04-03
    • 2020-03-05
    • 2018-07-17
    • 2021-10-25
    • 2018-09-20
    • 1970-01-01
    • 2019-05-18
    • 2012-07-29
    相关资源
    最近更新 更多