2017-10-09 107 views
0

如果我在本地運行我的應用程序(使用本地主機),它可以很好地工作。爲什麼我的前端不從我的後端檢索信息?

但是,當我決定切換到我的全球IP地址(當我說全球我的意思不是我的LAN 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

而且我已經在我的路由器和防火牆中打開了端口。

現在,在我的路由器中,我只打開了端口:45510764714​​,因爲這是在我的前端運行的端口,而在我的後端運行的是52889

我該做什麼錯?

+0

可能嘗試改變這個'--host 0.0 .0.0'到'--host my-isp' –

+0

我已經試過了,它說ip不能被綁定。 – RottenCheese

回答

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作爲管理員...

相關問題