6

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
Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Set
  • 47,577
  • 22
  • 132
  • 150

1 Answers1

2

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 2
    still listening on default port – Set Aug 23 '16 at 11:15
  • 1
    @Set are you sure you passed `--server.urls=http://0.0.0.0:5002`? In your updated question you use `--server.url` (with out the `s`). – Henk Mollema Aug 23 '16 at 11:38
  • 1
    The correct configuration settings is now just "urls". So change your hosting.json to { "urls": "http://0.0.0.0:5001" } – cbp Sep 04 '17 at 05:11
  • 1
    @cbp: The question was about "change Kestrel listening port from **command line**". The information about `hosting.json` is described in [the old answer](https://stackoverflow.com/a/34221690/315935) for example, which I referenced too. – Oleg Sep 04 '17 at 06:36