user12949382
user12949382

Reputation:

Accessing .net Core API via azure VM throws ERR_CONNECTION_REFUSED

I've set up a linux VM using Azure and I have the public IP from that machine.

I've cloned my repo inside that machine and I run dotnet run and I get the output:

Hosting environment: Development
Content root path: /home/g67Admin/projeto_integrador_grupo67/mdv
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Then I try to go to: https://(public IP):5001/api/Drivers and I cannot access it, gives me this error ERR_CONNECTION_REFUSED.

I've went to the azure portal and tried to authorize the ports 5000 and 5001 from any source to any source, rebooted the machine multiple times and still get connection refused.

How can I solve this?

Upvotes: 1

Views: 644

Answers (1)

Alex
Alex

Reputation: 18556

By default, your local development server won't listen on your public IP or allow traffic from any other machine in your network. It only listens on localhost. You need to explicitly bind other urls to your server.

https://weblog.west-wind.com/posts/2016/sep/28/external-network-access-to-kestrel-and-iis-express-in-aspnet-core

You can run your code like this:

dotnet run --urls http://0.0.0.0:5001

Or you can use Use WebHost.UseUrls() to achieve a similar result.

Upvotes: 2

Related Questions