Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1535

How to reconfigure Kestrel after start application

$
0
0

I have method for Kestrel configuration before starting asp.net core minimal API like this:

var clientCertificateThumbprint = "XYZ";var clientCertificateMode = ClientCertificateMode.RequireCertificate;var listeningPort = 11101;var tlsProtocol = SslProtocols.Tls12;var cert = CertificationService.GetCert();_builder.ConfigureKestrel(options =>{    options.ListenAnyIP(listeningPort, listenOptions =>    {        listenOptions.UseHttps(cert, (httpsOptions) =>        {            httpsOptions.SslProtocols = tlsProtocol;            httpsOptions.ClientCertificateMode = clientCertificateMode;            httpsOptions.ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => ValidateClientCertificate(certificate, clientCertificateThumbprint);        });    });});private bool ValidateClientCertificate(X509Certificate2? certificate, string thumbprint){    return certificate is null || DateTime.Now > certificate.NotAfter ? false : certificate.Thumbprint.Equals(thumbprint, StringComparison.OrdinalIgnoreCase);}

But if I call the same method after application started, it fails with:

System.InvalidOperationException: 'The service collection cannot be modified because it is read-only.'

Is there any way how to achieve this?

I cannot use autoreaload from appsettings file, because all this configuration parameters comes from database. But if Kestrel can apply changes from appsettings file, there sholud be exist a way how to do it manually at runtime.


Viewing all articles
Browse latest Browse all 1535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>