and Deployment

Kestrel. Configuring Listening Address

Using Kestrel you can specify port using next approaches:

  1. Defining ASPNETCORE_URLS environment variable.



    OS X

  2. Via command line passing --server.urls parameter

    dotnet run --server.urls=
  3. Using UseUrls() method

    var builder = new WebHostBuilder()
  4. Defining server.urls setting in configuration source.

Next sample use hosting.json file for example.

Add `hosting.json` with the following content to you project:

       "server.urls": "http://<ip address>:<port>" 

Examples of posible values:

  • listen 5000 on any IP4 and IP6 addresses from any interface:

     "server.urls": "http://*:5000" 


     "server.urls": "http://::5000;"
  • listen 5000 on every IP4 address:

     "server.urls": ""

One should be carefully and not use http://*:5000;http://::5000, http://::5000;http://*:5000, http://*:5000; or http://*:5000; because it will require to register IP6 address :: or IP4 address twice

Add file to publishOptions in project.json

"publishOptions": {
"include": [

and in entry point for the application call .UseConfiguration(config) when creating WebHostBuilder:

public static void Main(string[] args)
    var config = new ConfigurationBuilder()
        .AddJsonFile("hosting.json", optional: true)

    var host = new WebHostBuilder()