如果我在本地运行我的应用程序(使用localhost),它可以很好地工作。
但是当我决定切换到我的全球IP地址时(当我说全局时我的意思不是我的局域网地址,而是我的ISP提供的地址)。
它只是不加载我后端的数据。
这是我从前端发出请求的方式:
this.http.get("http://my-isp-ip:52899/api/Student/ListStudents").subscribe(response => {
this.users = response["Users"];
});
这就是我在后端获取applicationhost.config的方式:
<bindings>
<binding protocol="http" bindingInformation="*:52899:localhost" />
<binding protocol="http" bindingInformation="*:52899:my-isp-ip" />
</bindings>
我运行这样的前端应用程序:
ng serve --host 0.0.0.0
我已经在路由器和防火墙上打开了端口。
现在,在我的路由器中,我只打开了端口:4200
,因为这是在我的前端运行的端口,而52889
是在我的后端运行的端口。
我可以做错什么?
答案 0 :(得分:0)
<强>解决方案:强> 我改变了:
<bindings>
<binding protocol="http" bindingInformation="*:52899:localhost" />
<binding protocol="http" bindingInformation="*:52899:my-isp-ip" />
</bindings>
要:
<bindings>
<binding protocol="http" bindingInformation="*:52899:localhost" />
<binding protocol="http" bindingInformation="*:52899:*" />
</bindings>
以管理员身份运行Visual Studio ...