【发布时间】: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