1

Before marking it duplicate please read through.

I am using simple web hosting option from Visual Studio 2015, which hosts the default template web api over localhost:5000 port.

Please note that I am not using IIS express, a lot of questions out there are for IIS hosting.

I can consume them simply using http://localhost:5000/api/values. However when I try to consume this api from another system which is on LAN, using appropriate IP instead of localhost, it simply can't connect and shows error connecting to url.

You can try to reproduce this easily:

  1. Create an ASP .NET 5 web api using Visual Studio 2015.
  2. Select the "web" option inspite of "IIS Express" while running the solution. This would the ASP .NET web api using console over port 5000.
  3. Now we can consume the web api by hitting : http://localhost:5000/api/values
  4. However if I try to do the same from another system over LAN (changing localhost to appropriate IP), I can't connect.
  5. Also, If I try to ping my system from another system over LAN, I get appropriate response.

Any help would be appreciated.

4
  • Seems like it's denying every access but from localhost. What happens when you properly publish the app and then start it? I bet it doesn't behave this way when employed. There must be some config switch to make it behave the way you want (i.e. don't deny access for everyone but localhost) Mar 25, 2016 at 13:45
  • If I host it using IIS, and then try to access it from remote computer over LAN, still I can't get it working. I get message "HTTP Error 400. The request hostname is invalid" in this case. Mar 25, 2016 at 13:52
  • Might be because of the wrong contents of the Host: ... field in that HTTP request. Try setting it to localhost or <network ip> maybe? All in all, if you employ / publish your web-app, those inaccessibility problems should go anyways. Mar 25, 2016 at 14:05
  • I am using network IP address, I am able to ping that IP. But can't access web api. Mar 25, 2016 at 14:09

1 Answer 1

2

Edit the project.json file, find the "commands" section and edit the value of the "web" key to be as follows:

"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:5000"

This will cause Kestrel to listen on all addresses from all interfaces. You should also check the firewall settings; is 5000 blocked?

4
  • Wow. that worked. But is that the perfect solution ? Mar 25, 2016 at 16:05
  • Looks like that is the solution. I am marking it answered. Could also please tell me some references to learn about this ? Mar 25, 2016 at 16:13
  • @DotnetRocks - looks like a good overview can be found here: docs.asp.net/en/latest/fundamentals/…
    – Rob Davis
    Mar 25, 2016 at 16:21
  • thanks :-) . Lots of new things which I need to catch up with. Mar 25, 2016 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.