Skip to content

Specifying a Port Number to the dotnet run Command in ASP.Net Core

ASP.Net core lets you run a web server for your web application from the command line with the command:

dotnet run

But there is no command argument passing the port to listen on. For example in Ruby on Rails you could specify the port with the –port (-p) argument:

rails server --port 2000

Instead ASP.Net Core uses the environment variable ASPNETCORE_URLS to take a string representation of the port and hostname of the server. If you want to change the port that the server listens on at the command line you will need to set the environment variable. Which you can do within the scope of the command:

It would be much nicer if ASP.NET Core supported this in a similar way to rails but it seems the team has taken a different approach to configuration – relying on environment variables. Its the same if you need to specify the environment too.

Published in.NET Core

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *