如何使用机器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>();
});
任何建议或指南将不胜感激,在此先感谢!
答案 0 :(得分:0)
最后,我发现自己犯了一个愚蠢的错误。
我必须按照以下方式传递IP地址:
serverOptions.Listen(IPAddress.Parse("192.168.0.101"), 5001, ....