Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change Kestrel listening port from command line

I have the following entry point:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("hosting.json", optional: true)
        .AddCommandLine(args)
        .AddEnvironmentVariables()
        .Build();

    var host = new WebHostBuilder()
        .UseConfiguration(config)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

It works if I add hosting.json file like

{
  "server.urls": "http://0.0.0.0:5001"
}

or if I define environment variable (have found name here)

SET ASPNETCORE_URLS=https://0.0.0.0:5001

But if I pass --server.urls http://0.0.0.0:5001 as parameter, the app listening the default 5000 port:

> dotnet run --server.urls http://0.0.0.0:5001
...
Now listening on: http://localhost:5000
like image 479
Set Avatar asked Aug 23 '16 10:08

Set


1 Answers

The correct syntax is

dotnet run --server.urls=http://0.0.0.0:5001

instead of

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

See the old answer for more details.

like image 195
Oleg Avatar answered Oct 06 '22 02:10

Oleg