Using appsettings.json to configure Kestrel listen port Dotnet core 2 preview 2

前端 未结 5 1174
别跟我提以往
别跟我提以往 2020-12-08 10:07

From what I understand the correct way of setting listen ports for ASP Dotnet Core 2 preview 1/2 is by creating a Kestrel section in the appsettings.json in the following fo

5条回答
  •  庸人自扰
    2020-12-08 10:38

    I am using Program.cs and hosting.json file to configure Kestrel. Example:

        var config = new ConfigurationBuilder()
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("hosting.json", optional: true, reloadOnChange: true)
                        .Build();
    
        var host = new WebHostBuilder()
                        .UseConfiguration(config)
                        .UseKestrel()
                        .UseContentRoot(Directory.GetCurrentDirectory())
                        .UseStartup();
    

    hosting.json:

    {
        "urls": "http://localhost:4444;http://localhost:4445;"
    }
    

    This above is an example for the latest version dotnet core.

    For earlier versions:

    hosting.json:

    {
        "server.urls": "http://localhost:4444;http://localhost:4445;"
    }
    

提交回复
热议问题