ASP.NET Core by Patrik

Why ASP.NET Core Ignores Your Port Setting When Running from Command Line

When you run an ASP.NET Core API from the command line, it will not use the port defined in launchSettings.json. This often surprises developers, but it is normal behavior.
The reason is simple: launchSettings.json is only used by Visual Studio or other IDEs during debugging.
To make your app listen on a specific port when running with dotnet run or dotnet MyApi.dll, you must configure the port using runtime options such as command-line arguments, environment variables, or appsettings.json.

Key Points

  • launchSettings.json does not apply when starting the app from the console.
  • Use dotnet run --urls "http://localhost:5050" to force a port.
  • Or set an environment variable:
    ASPNETCORE_URLS=http://localhost:5050
  • For a permanent app-level setting, use appsettings.json to define Kestrel endpoints.
  • Use http://0.0.0.0:5050 if running inside Docker or WSL.
aspnetcore
kestrel
configuration
webapi
ports

Comments