Apologies if this could have been asked before. We hve tried this link from StackOverflow and didn't work for us either Bad Request - Invalid Hostname when accessing localhost Web API or Web App from across LAN.
We have a .net core 2.0 web api configured in one of the laptops with the following ip address:

and running on windows 10, and Visual Studio 2017

The project settings:

We have modified the applicationsHost config file as well for the project and added the IPAddress of the machine with the correct port on the bindings

We run the following commands too netsh https add urlacl url=http://192.168.43.192:51785/ user=everyone netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=51785 profile=private remoteip=localsubnet action=allow
We have included the said ports as well on the firewall rules (inboud/outbound):

The problem is that when we access the web api from a different machine on the network (different ip address, can be a Mac or a mobile device either via port 44350, ssl, or port 51785) it always return an error
Thanks in advance for the help.
I'm currently working on the road and using my phone (on the picture above as the router hence no wifi connection icon on the android). It works the same on my mac which is connected to the android phone's wifi as well. Also, I get the same if I'm using a fixed router at home.
We even tried to download Conveyor from here https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti
As IIS Express is stupid to accept remote connections, run Kestrel alone and set UseUrls in Program.cs file
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://*:[your port]")
If want to use IIS Express:
you need to forward port, it seems that this thing checks if the connection sends host header that matches what it is bound with or being 127.0.0.1 if not bound.
.vs\config\applicationhost.config<binding protocol="http" bindingInformation="*:[port]:localhost"> Change it to: <binding protocol="http" bindingInformation="*:[port]:" />
Create port forwarding, from cmd:
netsh interface portproxy add v4tov4 listenport=[new-port] listenaddress=* connectport=[the-port-iis-using] connectaddress=127.0.0.1
[new-port]Did you try our extension 'Conveyor' that was mentioned in that post? You can get Conveyor from the extensions dialog or https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti it fixes the 400 Bad Request error from IIS Express without any config changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With