When I try to hit my web app on port 8080 I get the following error
Bad Request - Invalid Hostname
HTTP Error 400. The request hostname is inval
For Visual Studio 2017
and Visual Studio 2015
, IIS Express
settings is stored in the hidden .vs
directory and the path is something like this .vs\config\applicationhost.config
, add binding like below will work
<bindings>
<binding protocol="http" bindingInformation="*:8802:localhost" />
<binding protocol="http" bindingInformation="*:8802:127.0.0.1" />
</bindings>
Syntax: https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.administration.binding.bindinginformation?view=iis-dotnet
Don't forget to bind to the IPv6 address as well! I was trying to add a site on 127.0.0.1 using localhost and got the bad request/invalid hostname error. When I pinged localhost it resolved to ::1 since IPv6 was enabled so I just had to add the additional binding to fix the issue.
Check your local hosts file (C:\Windows\System32\drivers\etc\hosts for example). In my case I had previously used this to point a URL to a dev box and then forgotten about it. When I then reused the same URL I kept getting Bad Request (Invalid Hostname) because the traffic was going to the wrong server.