我有一个ASPWindowsCore1.1WebAPI和Web App运行在我的本地主机上,来自.Net 10上的Visual Studio2017。
当我运行项目时,API在http://localhost:50082/api/上运行,web应用程序在http://localhost:60856/上运行。
但是,如果局域网上的其他人试图访问它(使用我计算机的IP地址- http://192.168.1.101:60856/ ),他们会得到一个
错误的请求-主机名无效
错误。事实上,。我也收到这个错误,因为我使用我的IP地址。我已经在我的C:\Users\Documents\IISExpress\config\applicationhost.config文件中尝试了大约12种变体,例如:
<bindings>
<binding protocol="http" bindingInformation="*:60856:localhost" />
</bindings>和
<bindings>
<binding protocol="http" bindingInformation="*:60856:" />
</bindings>每次重新启动项目(以及IIS Express),但似乎都不起作用。有什么想法吗?
发布于 2017-07-18 00:11:53
默认情况下,IIS Express不允许远程连接。This post解释了如何激活它。
在我看来,如果您设置本地IIS并将应用程序发布到配置的IIS文件夹,会更好。
我已经在其他情况下尝试了HTTP.SYS配置,有时配置会丢失,无论是在重启还是windows更新时...但这可能不会发生在你身上。
发布于 2021-04-14 03:55:31
我在尝试让ngrok指向本地的ASP.NET核心网站时也遇到了同样的问题。
这家伙的回答对我很管用: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]:*" />发布于 2021-09-09 11:10:07
如果你使用的是asp core,另一个解决方案是简单地从Visual Studio工具栏将你的配置文件从'IIS‘更改为'Standalone’(命名为你的项目):

通过此更改,IIS将不再运行,嵌入式asp web服务器'kestrel‘将直接面对请求。
如果仍然显示host invalid错误,请通过将以下行添加到配置文件中来调整主机名设置:
"AllowedHosts": "*",更多信息:
https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-with-ASPNET-Core-22
https://stackoverflow.com/questions/45147241
复制相似问题