3

I created a simple Asp.net Web Api. When I run the code Chrome is opening and getting xml data from sql server database. Here is the link: http://localhost:50599/api/Menu/. And this my output: https://i.stack.imgur.com/hKeZd.png

But when I put my local address instead of "localhost" it gives me 400 error. My IIs is running. when I enter 127.0.0.1 or 192.168.1.104 or localhost IIS page is opening.

I did everything for opening 127.0.0.1:50599/api/menu or 192.168.1.104:50599/api/menu but error 400 apears. I changed

<binding protocol="http" bindingInformation="*:8080:localhost" /> 

to

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

and it didnt work for me.

How can I solve this problem. If I can make this work I will access this Api from an android device.

mason
  • 31,774
  • 10
  • 77
  • 121
Nicat Güliyev
  • 97
  • 2
  • 10
  • Quick check: your "working" config is using port `50599` (not `8080`). – EdSF Nov 25 '17 at 18:38
  • But in applicationHost.config file Port is 8080. I changed 8080 to 505999 but it didnt work. – Nicat Güliyev Nov 25 '17 at 18:45
  • what do you mean by `local address` - your computer name? try a `ping` on your local address, and see if any ip address is resolved. – Frank Nielsen Nov 25 '17 at 19:25
  • my ip adress is 192.168.1.104 – Nicat Güliyev Nov 25 '17 at 19:40
  • @NicatGüliyev 192.168.x.x cannot go over the Internet. It is a local address for local hosts. Local means a close neighbour. You should search Google for "400 error". – Andrew Morton Nov 25 '17 at 21:58
  • @AndrewMorton I know that 192.168.1.104 is local adress. And My Android device is connected same Network. If i write 192.168.1.104 in browser in android device it is connected to my Computer. And In android device IIS page openning. But if i write 192.168.1.104:50590/api/Menu in computer and Android device they are not connected to Web api. But if i write localhost:50590/api/menu in computer, i can connected to my Web api. – Nicat Güliyev Nov 26 '17 at 06:36
  • Does this answer your question? [Can't access WEB API with ip:port but can with localhost:port during VS debug mode](https://stackoverflow.com/questions/19554996/cant-access-web-api-with-ipport-but-can-with-localhostport-during-vs-debug-mo) – Carlos López Marí Mar 26 '20 at 09:34

1 Answers1

11

I ran into the same problem you did and I know I'll be repeating some of the stuff you did but try to bear with me.

Edit the applicationhost.config in the root solution folder. It's in a hidden folder called .vs.

In your site, add:

<binding protocol="http" bindingInformation="*:port:*" />
<binding protocol="http" bindingInformation="*:port:youripaddress" />

If you see 8080 which is the default port, you are in the wrong section.

Open Visual Studio in administrator mode.

Tong
  • 697
  • 1
  • 8
  • 16
  • Great to find out this answer. Also, the 'Open VS in Administrator' is important. Took me few minutes to find out I overlook the last sentence. – zeroflaw Apr 19 '23 at 03:22