简体   繁体   中英

How to override default ports in Kestrel

i have simple method

public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>());
        }

and i am write appsettings:

"Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http1AndHttp2"
    },
    "Endpoints": {
      "Api": {
        "Url": "https://+:5005",
        "Protocols": "Http1AndHttp2"
      },
      "Grpc": {
        "Url": "http://+:5006",
        "Protocols": "Http2"
      }
    }
  }

but when i start app, i see warning:

"Microsoft.AspNetCore.Server.Kestrel", "message": "Overriding address(es) 'https:\/\/localhost:5000, https:\/\/localhost:5001'. Binding to endpoints defined in UseKestrel() instead.", "addresses": "https:\/\/localhost:5000, https:\/\/localhost:5001
", "methodName": "UseKestrel()" }

and app start at standard port 5000, but i expect on port 5005

Why Kestrel changes the start port and how to make the application start on a given https://localhost:5005/api-docs/someService (i am use swagger)

As said on your application startup just do it in UseKestrel()

return Host.CreateDefaultBuilder(args)
       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
       .ConfigureWebHostDefaults(builder => builder.UseKestrel(x=>x.Listen(IPAddress.Any, 5005)).UseStartup<Startup>());

i am find that i need feel launchSettings.json with

"launchUrl": "https://localhost:5005/api-docs/SomeService"
  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM