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

前端 未结 5 1180
别跟我提以往
别跟我提以往 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:33

    Support for Kestrel configuration via appsettings.json has been dropped in 2.0.

    See this issue comment:

    kestrel config file support was cut from 2.0.0. Config values need to be read manually in your initialization code.

    To get around this, you can do something like this in program.cs:

    public static IWebHost BuildWebHost(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
     .UseStartup < Startup > ()
     .UseKestrel((hostingContext, options) => 
     { 
      if (hostingContext.HostingEnvironment.IsDevelopment) {
       options.Listen(IPAddress.Loopback, 9001);
       options.Listen(IPAddress.Loopback, 9002, listenOptions => {
        listenOptions.UseHttps("certificate.pfx", "password");
       });
      }
    
     })
     .Build();
    

提交回复
热议问题