以下代码运行并在Azure应用程序服务上运行时获取应用数据。在当地,证书未授权的例外。有什么原因吗?
如果我从字符串本地创建证书,则可以正常工作。
public static CertificateCloudCredentials CredentialsProd;
X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
prodThumbprint,
false);
if (certCollection.Count > 0)
{
X509Certificate2 cert = certCollection[0];
Credentials = new CertificateCloudCredentials(SUBSCRIPTION_ID, cert);
}
certStore.Close();
using (var client = new ComputeManagementClient(Credentials))
{
var t = client.HostedServices.GetDetailedAsync(serviceName, CancellationToken);
HostedServiceGetDetailedResponse detailedResponse = t.Result;
}
本地计算机上的证书必须安装为.pfx就像在Azure中一样。