所以我正在连接到第三方 api,它需要加载 .p12 证书才能进行身份验证。在本地主机上一切正常,但在远程共享主机上我收到可怕的“请求已中止:无法创建 SSL/TLS 安全通道”错误。我的网站是 asp.net Framework 4.7,并且有安全的 ssl 连接。我已经添加了
'System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Global.asax(如果不是,它甚至不会在本地主机上运行)。感谢任何有关如何解决此问题的提示。
这是在本地主机上运行良好的测试代码:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim certPath As String = Server.MapPath("~/BolsasPixCert.p12")
Dim uidCert As X509Certificate2 = New X509Certificate2(certPath, "")
Dim options = New RestClientOptions("https://pix.api.efipay.com.br") With {
.ClientCertificates = New X509CertificateCollection() From {
uidCert
},
.ThrowOnAnyError = True
}
好吧,我终于在 smarterasp.net KB 上找到了答案:
添加X509KeyStorageFlags.MachineKeySet:
Dim uidCert As X509Certificate2 = New X509Certificate2(certPath, "",X509KeyStorageFlags.MachineKeySet)
确保您引用 bin 文件夹中的 System.Net.Http.dll