错误请求-当从手机通过 wifi 连接到本地主机时,主机名无效

我在尝试连接笔记本本地主机时得到了 错误请求-无效主机名[ HTTP ERROR 400]。 事实上,我正在学习使用 jQueryMobile 开发移动网络。 我想看看网页的布局是否适合我的手机大小。

我用这种方式添加了 Visual Studio 给出的端口号:
控制面板 > 防火墙 > 高级设置 > 弹出规则 > 新规则
然后,通过在命令提示符下键入“ Ipconfig”来获得我的 IP 地址。
之后,我使用 Android 手机浏览器(Mozilla 5.0)并输入链接192.XXX.XXX.XXX: 57976。

我读过类似的问题,但我不能得到解决办法。 有些人认为这个错误与 IIS 设置有关。 但我无法得到 IIS 设置的解决方案。 希望你们能帮我解决这个问题。

123399 次浏览

Step 1: Add Inbound Rule of Windows Firewall

Windows Firewall

  1. Open the Windows Firewall with Advanced Security.
  2. At the left panel, right click on Inbound Rule > New Rule
  3. Rule Type: Port
    Protocol and Ports: TCP
    Specific local ports: 57976
    Action: Allow the connection
    Profile: Tick all (Domain, Private, Public)
    Name: Name, Description(optional)
  4. Finish.

Step 2: IIS or IIS Express

Add Bindings of IIS Manager

IIS Manager

  1. Open the IIS Manager.
  2. At the left panel, Go to Sites > Default Web Sites.
  3. At the right panel, click on the Bindings. Then, the new dialog pop ups.
  4. At the pop-up dialog, click on the "Add" buttons. Input the port number and the hostname.
    For my case,
    port = 57976;
    hostname = 192.XXX.XXX.XXX (my IP address)

Add Bindings of IIS Express (Visual Studio)

IIS Express

  1. Stop the current Site
  2. For Visual Studio 2015, change the IIS config under your project folder C:\Projects\<ProjectName>\.vs\config\applicationhost.config‌​.
  3. For previous version of Visual Studio 2015, change the IIS config under IIS Express folder C:\Users\<your profile name>\Documents\IISExpress\config\applicationhost.config
  4. In applicationhost.config, search by the port number (for my case is 57976), then one more binding with your IP Address

        <site name="Web(1)" id="9">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="E:\abc\project\dev\web" />
    </application>
    <bindings>
    <binding protocol="http" bindingInformation="*:57976:localhost" />
    <binding protocol="http" bindingInformation="*:57976:192.XXX.X.XXX" />
    </bindings>
    </site>
    

Updated:

For windows 10 or Visual Studio 2015 users, you may get the error message below:

Unable to launch the IIS Express Web server, Failed to register URL, Access is denied

Solution:

  1. Close Visual Studio
  2. Right click on Visual Studio > Run as Administrator



Reference: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-configure-iis-express/

Clear Browser data ctrl+shift+del