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

后端 未结 5 1818
天涯浪人
天涯浪人 2020-12-08 02:45

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 wo

相关标签:
5条回答
  • 2020-12-08 03:05

    Had the same issue debugging in Visual Studio Code, I solved it by adding:

    "env": {
          // ...
          "ASPNETCORE_URLS": "http://*:5000" // change to the port you are using
          // ...
    },
    

    .. to launch.json

    Apparently, by default it binds http protocol to 'localhost:5000', so it works with localhost but not with ip address.

    If you are trying to hit a breakpoint by a request coming from a different computer, don't forget to check your firewall settings (and/or antivirus)

    hope this helps

    0 讨论(0)
  • 2020-12-08 03:06

    If you're running it in debug mode I assume you're using IIS-Express.

    By default, IIS-Express only binds to localhost.

    To circumvent this, you can open the IIS-Express application config file located at: C:\Users\<username>\My Documents\IISExpress\config\applicationhost.config and modify the site's binding information.

    change

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

    to

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

    You'll also have to restart IIS-Express after the change.

    0 讨论(0)
  • 2020-12-08 03:13

    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 http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

      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,

    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)

    0 讨论(0)
  • 2020-12-08 03:14

    In your solution dir, in the file .vs\config\applicationHost.config change the line

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

    to

    <binding protocol="http" bindingInformation=":1234:192.168.1.35" />
    

    and run Visual Studio as an admin. Restart IIS Express. this solution work for me.

    0 讨论(0)
  • 2020-12-08 03:24

    I had the same problems when I wanted to share my localhost IIS so some guys could just type my machine name or IP and connect to my web app instance. So if this is what you need when http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer. It works for me for both Silverlight and MVC apps. I even set breakpoints and they are hit from a remote machine.

    0 讨论(0)
提交回复
热议问题