I have Kestrel section in appsettings.json and I also call ConfigureKestrel() in Program.cs. When I run the app, there is an error:
11:10:36 [Warning] () Overriding address(es) '"https://localhost:5003"'. Binding to endpoints defined in "UseKestrel()" instead.
11:10:36 [Fatal] () Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://[::]:5003: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use
Here is my appsettings.json:
"Kestrel": {
"Endpoints": {
"HttpsInlineCertFile": {
"Url": "https://localhost:5003",
"Certificate": {
"Path": "/tmp/localhost.pfx",
"Password": "password"
}
},
"HttpsDefaultCert": {
"Url": "https://localhost:5003"
},
"Https": {
"Url": "https://*:5003",
"Certificate": {
"Path": "/tmp/localhost.pfx",
"Password": "password"
}
}
},
"Certificates": {
"Default": {
"Path": "/tmp/localhost.pfx",
"Password": "password"
}
}
},
Here is my ConfigureKestrel():
.ConfigureKestrel((context, options) =>
{
options.Listen(IPAddress.Any, 5003, listenOptions =>
{
listenOptions.UseHttps(o => o.SslProtocols = SslProtocols.Tls12);
listenOptions.UseConnectionLogging();
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
});
});
OR:
.ConfigureKestrel((context, options) =>
{
options.Configure(context.Configuration.GetSection("Kestrel"))
.Endpoint("Https", listenOptions =>
{
listenOptions.HttpsOptions.SslProtocols = SslProtocols.Tls12;
listenOptions.ListenOptions.UseConnectionLogging();
listenOptions.ListenOptions.Protocols = HttpProtocols.Http1AndHttp2;
});
});
So, which is which? I am confused. Can I do everything in appsettings.json?
Update: I have figured out how to configure other options in appsettings.json except 2: listenOptions.HttpsOptions.SslProtocols
and UseConnectionLogging