Reputation: 6200
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:
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.
Upvotes: 4
Views: 12019
Reputation: 6200
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>
Upvotes: 5
Reputation: 4494
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 Configure Multiple Web Sites
Upvotes: 1