noobiehacker noobiehacker - 2 months ago 44
C# Question

Can't access WEB API with ip:port but can with localhost:port during VS debug mode

I am trying to write an WEB API from .net and trying for my Android Application to query some data from the sql server database.

I have the web api written and it works well in debug mode.

My question is I notice the url of that application is

and it runs fine.
However, when I try to change it to
MYIP:port (eg. http:192.168.X.1234)
MYHOSTNAME:port (eg win7home:1234)
this gives me
Bad Request - Invalid Hostname

I know I can deploy this to IIS and my IIS is setup but I was just wondering how come it doesn't work in debug mode???

Is there a way for me to run it in debug mode and test in on my Android at the same time instead of having to deploy it every time I want to make a change?


Both Anton and Matthew's Answers pointed me to the right direction

So this what I did

1)Run Visual Studios in administrator mode

2)Changed the binding protocols and allow for incoming directions as suggested

-But after that, I have a service unavailable (503) error

3)So I followed this : IIS Express Enable External Request - 503 Added just the port protocol and port:ip protocol,

    <binding protocol="http" bindingInformation=":1904:" />
    <binding protocol="http" bindingInformation=":1904:" />

Than it works both on my machine's browser and on my phone.

Not too too sure why the 3rd step is needed -my hypothesis is (the localhost url is needed for VS to point to and the ip url is used for accessing from another machine)