代码之家  ›  专栏  ›  技术社区  ›  Fabricio Rodriguez

错误的请求-跨LAN访问本地主机Web API或Web应用程序时主机名无效

  •  10
  • Fabricio Rodriguez  · 技术社区  · 9 年前

    http://localhost:50082/api/ 和web应用程序 http://localhost:60856/

    但是,如果局域网上的其他人尝试访问它(使用我的计算机的IP地址- http://192.168.1.101:60856/ 他们得到一个

    错误事实上我得到这个错误,我也使用我的IP地址。我在C:\Users\Documents\IISExpress\config\applicationhost中尝试了十几种变体。配置文件,例如:

    <bindings>
    <binding protocol="http" bindingInformation="*:60856:localhost" />
    </bindings>
    

    <bindings>
    <binding protocol="http" bindingInformation="*:60856:" />
    </bindings>
    

    每次都重新启动项目(因此IIS Express),但似乎什么都不起作用。有什么想法吗?

    3 回复  |  直到 9 年前
        1
  •  10
  •   João Pereira    9 年前

    默认情况下,IIS Express不允许远程连接。 This post

    在我看来,如果您安装本地IIS并将应用程序发布到配置的IIS文件夹中,您会感觉更好。

    我已经试过HTTP了。其他情况下的SYS配置,有时配置会丢失,无论是在重新启动或windows更新时…但这可能不会发生在您身上。。。

        2
  •  1
  •   HamedH    4 年前

    如果您使用的是asp core,另一种解决方案是从Visual Studio工具栏将您的配置文件从“IIS”更改为“Standalone”(即您的项目):

    enter image description here

    通过此更改,IIS将不再运行,嵌入式asp web服务器“kestrel” 将直接面对这些请求。

    "AllowedHosts": "*",
    

    更多信息:

    https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/?view=aspnetcore-5.0#set-up-a-reverse-proxy

    https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-with-ASPNET-Core-22

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/host-filtering?view=aspnetcore-5.0

        3
  •  0
  •   Lavamantis    5 年前

    我也有同样的问题 ngrok

    这家伙的回答对我很有用: 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]:*" />