I have tried the following two functions to configure Kestrel:
public static void UseKestralConfigurations(this WebApplicationBuilder builder)
{
_ = builder.Services.Configure<KestrelServerOptions>(options =>
{
options.ConfigureHttpsDefaults(options =>
{
options.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
options.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
//options.ClientCertificate
options.ClientCertificateValidation = (cert, chain, policyErrors) =>
// Certificate validation logic here
// Return true if the certificate is valid or false if it is invalid
true;
options.CheckCertificateRevocation = false;
options.ServerCertificate = LoadCertificate();
});
});
}
And the more modern UseKestrel():
public static void UseKestrel(this WebApplicationBuilder builder)
{
builder.WebHost.UseKestrel(options =>
{
options.ConfigureHttpsDefaults(defaults =>
{
defaults.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
defaults.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
// defaults.ClientCertificate
defaults.ClientCertificateValidation = (cert, chain, policyErrors) =>
// Certificate validation logic here
// Return true if the certificate is valid or false if it is invalid
true;
defaults.CheckCertificateRevocation = false;
defaults.ServerCertificate = LoadCertificate();
});
});
}
But neither works. When I am debugging, and first step into this function, it does not even seem to run Configure(), or UseKestrel() at all. This makes some sense since they run when the builder is built.
But when the builder is built and the app is created with var app = builder.Build()
, the inner function: options.ConfigureHttpsDefaults()
is never run. It just completely skips over this function. And never configures the ServerCertificate. So when the app is run (app.Run()
), it immediately throws the following error:
{"The endpoint HttpsInlineCertFile is missing the required 'Url' parameter."}