【发布时间】:2018-06-04 04:17:00
【问题描述】:
我从第三方公司获取数据,他们给了我证书,以便我可以访问他们的服务。在本地设置时,它在将 .cer 和 .pfx 安装到我的证书存储中后工作。但是,当代码在我的 Azure Web 应用程序上运行时,我无法让它工作,它会导致错误:
Could not establish trust relationship for the SSL/TLS secure channel with authority
在授予我的应用程序池对公共根证书 (IIS AppPool\AppPoolName) 的访问权限之前,我最初在本地收到了这个特定错误。感觉就像我现在在 Azure 上遇到了同样的错误。该代码肯定会找到证书(否则会引发错误),但它似乎无权使用它们。
我已按照本指南在我的网络应用中安装证书:https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/
这是我用来加载私有证书的代码:
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (certs == null || certs.Count == 0)
{
ExceptionUtils.ThrowDataError("Private certificate could not be found");
}
store.Close();
return certs[0];
我也尝试将 .pfx 添加到 App_Data 文件夹并像这样加载它:
var certPath = HttpContext.Current.Server.MapPath("~/App_Data/cert.pfx");
var bankIdCert = new X509Certificate2(certPath, "password");
但它会导致相同的错误。也许这意味着它无法访问公共证书?目前工作的本地版本和 azure 版本之间的唯一区别是:
- 在本地,公共证书存储在 LocalMachine location Root 中,私有证书存储在 LocalMachine location My 中
- 在 Azure 上上传时,两个证书都转到 CurrentUserMy
某些证书是否需要在 LocalMachine 上才能工作?
【问题讨论】:
标签: c# azure certificate azure-web-app-service