Bad Request- Invalid Hostname while connect to localhost via wifi from mobile phone
Step 1: Add Inbound Rule of Windows Firewall
- Open the Windows Firewall with Advanced Security.
- At the left panel, right click on Inbound Rule > New Rule
- 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) - Finish.
Step 2: IIS or IIS Express
Add Bindings of IIS Manager
- Open the IIS Manager.
- At the left panel, Go to Sites > Default Web Sites.
- At the right panel, click on the Bindings. Then, the new dialog pop ups.
- 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)
- Stop the current Site
- For Visual Studio 2015, change the IIS config under your project folder
C:\Projects\<ProjectName>\.vs\config\applicationhost.config
. - 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
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:
- Close Visual Studio
- 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/