服务器放在阿里云,且是用开发模式启动的,(dotnet run xxx.csproj),发现通过ip地址怎么也无法访问,以为是防火墙的问题,阿里云防火墙的端口确实是已经开了的,服务器的防火墙也开了,那是什么原因呢?
后来发现控制台提示
从 C:\xxx\Properties\launchSettings.json 使用启动设置...
Hosting environment: Development
Content root path: C:\xxx
Now listening on: http://localhost:5000
意识到 launchSettings.json 里的 ip 配为了 localhost ,然后把 http://localhost:5000/ 改成 http://*:5000/
终于解决。
---------------2023/1/6----------------------------------------------------------------------------
.net6了,现在这样写更方便
Program.cs里面
builder.WebHost.UseUrls(WebHelper.get_item("use_url"));
use_url 配置的是 http://*:5000