Getting HTTP Error 400 when using IP address instead of localhost

10,342

Solution 1

Solved it with this answer editing applicationhost.config that in VS2015 it's located in [Project Folder]\.vs\config\applicationhost.config:

Since the linked URL from Jack's answer is currently not working, and the solution (at least for me) was covered in the answer to another question, I will repeat the answer here:

You can have multiple bindings set. Therefore, you can setup bindings for every external address you wish to serve on, and it will work:

<bindings>
    <binding protocol="http" bindingInformation=":1904:" />
    <binding protocol="http" bindingInformation=":1904:machineName" />
    <binding protocol="http" bindingInformation=":1904:10.1.10.123" />
</bindings>

Also this was helpful. In my case I did:

<bindings>
    <binding protocol="http" bindingInformation=":1623:" />
    <binding protocol="http" bindingInformation=":1623:<my pc name>" />
    <binding protocol="http" bindingInformation=":1623:192.168.0.174" />
</bindings>

Solution 2

The IIS is a multi web site server. The way is distinct the site is by the host header name. So you need to setup that on your web site.

Please see this link to setup:

HOW TO: Use Host Header Names to Host Multiple Sites Using Host Header Names to Host Multiple Web Sites

How To Use Host Header Names to Configure Multiple Web Sites

Share:
10,342
Andres
Author by

Andres

Electronics engineer with a passion for web development and embedded systems. Experience in high-level and low-level programming and hardware design!

Updated on June 09, 2022

Comments

  • Andres
    Andres almost 2 years

    I created a simple Web App with a Rest API with C# and VS2015. The web app is running in http://localhost:1623 and it works fine.

    Now I'm testing the Rest API doing a POST with Postman, my url is for example http://localhost:1623/api/foo/bar with a header Content-Type: application/json. Everything works great, I get the response correctly.

    The local IP address of my PC is 192.168.0.174, so I change the url to http://192.168.0.174:1623/api/foo/bar and now I get HTTP Error 400. The request hostname is invalid, why? Shouldn't it be the same?. The same happens (I get exactly the same error) if I try to access my Web App using 192.168.0.174:1623 instead of http://localhost:1623 in my browser:

    enter image description here

    I get the same error when trying to use the API from some device other device in my LAN using my IP. I need to use the IP because I need to access it from my network, why doesn't it work, what am I missing? I tried this and this with no success.

  • Andres
    Andres over 8 years
    I have IIS 10, I couldn't find the Multiple identities for this Web Site option but I have this setted in my bindings i.imgur.com/HCldO28.png but still doesn't work