Asp.NET core apps bind to the "localhost" network interface with default settings. This network interface is not available from other hosts.
You can modify this using UseUrls()
during host setup.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseUrls("http://0.0.0.0:5001");
});
Examples:
webBuilder.UseUrls("http://127.0.0.1:5001"); // only from localhost
webBuilder.UseUrls("http://localhost:5001"); // only from localhost
webBuilder.UseUrls("http://0.0.0.0:5001"); // allow all hosts
Docs: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-in-aspnet-core-apps
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…