錯誤請求 - 從跨 LAN 訪問 localhost Web API 或 Web 應用程序時主機名無效
我在 Windows 10 上的 Visual Studio 2017 的本地主機上執行了一個 ASP .Net Core 1.1 Web API 和 Web 應用程序。
當我執行項目時,API 在http://localhost:50082/api/上執行,Web 應用在http://localhost:60856/上執行
但是,如果 LAN 上的其他人嘗試訪問它(使用我電腦的 IP 地址 - http://192.168.1.101:60856/他們會得到一個
錯誤請求 - 無效的主機名
錯誤。實際上,。我也收到此錯誤,因為我使用了我的 IP 地址。我在 C:\Users\Documents\IISExpress\config\applicationhost.config 文件中嘗試了十幾種變體,例如:
<bindings> <binding protocol="http" bindingInformation="*:60856:localhost" /> </bindings>和
<bindings> <binding protocol="http" bindingInformation="*:60856:" /> </bindings>每次都重新啟動項目(以及因此 IIS Express),但似乎沒有任何效果。有任何想法嗎?
預設情況下,IIS Express 不允許遠端連接。這篇文章解釋瞭如何啟動它。
在我看來,如果你設置本地 IIS 並將應用程序發佈到配置的 IIS 文件夾,你會更好。
我已經嘗試過其他情況下的 HTTP.SYS 配置,有時無論是重新啟動還是 Windows 更新,配置都會失去……但這可能不會發生在你身上……
我在嘗試
ngrok指向本地 ASP.NET Core 網站時遇到了同樣的問題。這個人的回答對我有用:https ://kodlogs.com/blog/532/iis-express-http-error-400-the-request-hostname-is-invalid
基本上,在
[solution dir]\.vs\[asp.net core web app dir]\config\applicationhost.config文件中,將行從:<binding protocol="https" bindingInformation="*:[your port]:localhost" />到:
<binding protocol="https" bindingInformation="*:[your port]:*" />