Bad Request - Invalid Hostname IIS7

Solution 1:

Did you check the binding is IIS? (inetmgr.exe) It may not be registered to accept all hostnames on 8080.

For example, if you set it up for mysite.com:8080 and hit it at localhost:8080, IIS will get the request but not have a hostname binding to match so it rejects.

Outside of that, you should check the IIS logs (C:\inetpub\logs\wmsvc#) on the server and see if you are seeing your request. Then you'll know if its a problem on your client or on the server itself.

Solution 2:

FWIW, if you'd like to just allow requests directed to any hostname/ip then you can set your binding like so:

<binding protocol="http" bindingInformation="*:80:*" />

I use this binding so that I can load a VM with IE6 and then debug my application.


EDIT: While using IIS Express to debug, the default location for this option's config file is

C:\Users\{User}\Documents\IISExpress\config\applicationhost.config

Solution 3:

This page by Microsoft describes how to set up access to IIS Server Express from other computers on the local network.

In a nutshell:

1) from a command prompt with admin privileges:

netsh http add urlacl url=http://[your ip address]:8181/ user=everyone

2) In Windows Firewall with Advanced Security, create a new inbound rule for port 8181 to allow external connections

3) In applicationhost.config, in the node for your project, add:

<binding protocol="http" bindingInformation="*:8181:[your ip address]" />

Do NOT add (as was suggested in another answer):

<binding protocol="http" bindingInformation="*:8181:*" />

The above wildcard binding broke my access from http://192.168.1.6:8181/

Solution 4:

So, I solved this by going to my website in IIS Manager and changing the host name in site bindings from localhost to *. Started working immediately.

Site Bindings in IIS

Solution 5:

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