这是我在Kestrel中成功做到的方式: 1.在Startup.cs中:
var bytes = File.ReadAllBytes(certPath);
X509Certificate2 certificate = new X509Certificate2(bytes);
在httpclientfactory中:
services.AddHttpClient(“ ClientName”),客户端=> { client.BaseAddress = new Uri(Configuration.GetValue(“ BConfigurations:BaseAddress”)); } .ConfigurePrimaryHttpMessageHandler(()=>新的HttpClientHandler { ClientCertificates = {证书}, ClientCertificateOptions = ClientCertificateOption.Manual });
但是当我在IIS上发布内部版本时,我遇到了以下异常:(这在Kestrel中从未发生过)
WindowsCryptographicException:指定的网络密码不是 正确的Internal.Cryptography.Pal.CertificatePal.FilterPFXStore