3

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:

current .net machine IP 192.168.43.192

and running on windows 10, and Visual Studio 2017

Windows 10 Visual Studio Enterprise 2017 Version 15.5.2

The project settings: .net core web api project settings HTTPS Port 44350 and HTTP 51785

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

enter image description here

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): Inbound Firewall Rule allowed TCP Port 44350 and 51785 Outbound firewall rule allowed TCP Port 44350 and 51785

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

service unavailable - http error 501 on http 51785 bad request - invalid hostname http error 400 the request hostname is invalid on https port 44350 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

Nkosi
  • 191,971
  • 29
  • 311
  • 378
Travellogger
  • 79
  • 1
  • 6
  • Please provide text instead of screenshots of text. Your alt text doesn't actually say what's in the image so your question reads as, *We have a .net core 2.0 web api configured in one of the laptops with the following ip address: current .net machine* instead of providing users who can't see your images the actual IP address. – BSMP Jan 15 '18 at 12:21
  • Thanks BSMP, the current ip address is 192.168.43.192 (machine with the project and asp.net) – Travellogger Jan 15 '18 at 12:51
  • Have you confirmed that you're not actually getting to the remote machine and its code is returning the 400? Also, you indicate you tried the SO link, did you follow the link in the answer to enable remote access for IIS Express? – Craig W. Jan 16 '18 at 16:53
  • Hi yes we did try to update the applicationhosts config file for iis express – Travellogger Jan 19 '18 at 01:11
  • I modified again the question with a sample of what i'm getting on ssl and http ports from a mobile device/remote computer – Travellogger Jan 19 '18 at 03:52

2 Answers2

2

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.

  • Stop IIS Express
  • Open .vs\config\applicationhost.config
  • Find <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

  • Add firewall inbound rule for [new-port]
  • now you can call the api remotely using the ip and new port
0

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.