如果我在本地运行我的应用程序(使用本地主机),它可以完美运行。
但是当我决定切换到我的全局 IP 地址时(当我说全局时,我的意思不是我的局域网 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
是在我的后端上运行的端口。
我能做错什么?
解决方案:我改变了:
<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...