我有 Windows Server 2016 Data center x64、.NET Core SDK 5.0 预览版、Microsoft SQL Server 2019
在服务器上: https://localhost:5001/publisher/all ok
在服务器上https://127.0.0.1:5001/publisher/all https://127.0.0.1:5001/publisher/all ok
在服务器上:防火墙开放端口 5000-6000 出站
从我的电脑(或世界上任何一台电脑)https://45.118.145.72:5011/publisher/all https://45.118.145.72:5011/publisher/all not ok
如何访问https://45.118.145.72:5011/publisher/all https://45.118.145.72:5011/publisher/all来自公共互联网?
Asp.NET Core 应用程序使用默认设置绑定到“localhost”网络接口。其他主机无法使用此网络接口。
您可以使用修改它UseUrls()
在主机设置期间。
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseUrls("http://0.0.0.0:5001");
});
例子:
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://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-in-aspnet-core-apps https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-in-aspnet-core-apps
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)