Код: Выделить всё
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
string pass = @"my_complicated_password";
var cert = new X509Certificate2(@"C:\certs\my_server_cert.pfx", pass);
webBuilder.ConfigureKestrel(o =>
{
o.ConfigureHttpsDefaults(defaults =>
{
defaults.ServerCertificate = cert;
defaults.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
defaults.AllowAnyClientCertificate();
});
});
webBuilder.UseKestrel(options =>
{
options.ListenAnyIP(8384, o =>
{
o.UseHttps();
});
});
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webBuilder.UseStartup();
});
}
< /code>
Теперь, когда я работаю локально, я вижу следующее < /p>
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'https://localhost:8384'. Binding to endpoints defined in UseKestrel() instead.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://[::]:8384
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\location_of_web_app
crit: MyNameSpace.CertificateValidationService[1]
WE ARE IN THE VALIDATE CERT SECTION
crit: MyNameSpace.CertificateValidationService[2]
THE CERT BEING PASSED WAS THE_PERSON```
< /code>
Это то, что я ожидал. Однако на производстве я вижу следующее: < /p>
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://[::]:8384
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\my_app_location
warn: Microsoft.AspNetCore.Authentication.Certificate.CertificateAuthenticationHandler[2]
Certificate validation failed, subject was [All the stuff
PartialChain A certificate chain could not be built to a trusted root authority.
RevocationStatusUnknown The revocation function was unable to check revocation for the certificate.
OfflineRevocation The revocation function was unable to check revocation because the revocation server was offline.
Подробнее здесь: https://stackoverflow.com/questions/703 ... ionhandler