actively refused it 🟪 .NET

HttpRequestException: No connection could be made because the target machine actively refused it (localhost:5001)

Nothing is listening on the host/port the client called — the API isn’t running, uses another port, or the container/network address is wrong.

Seen on: .NET

Meaning

“Actively refused” means the TCP connection got a reset. Calling localhost from inside Docker, using http vs https ports incorrectly, or the service crashed at startup are typical.

Common causes

  • Target service not running or crashed
  • Wrong port (http vs https, launchSettings change)
  • localhost used inside a container
  • Firewall rejecting

⚡ Quick fix

  1. Check the service is running and the port it listens on
  2. Use the Docker service name / host.docker.internal
  3. Match the base address to the API’s URLs

Detailed fix by platform

Shell

  1. csharp
    netstat -ano | findstr :5001
    curl -v http://localhost:5000/health

How to diagnose

  1. Listening — Port open?
  2. Address — Base URL correct for the environment?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.