在 Azure App 服务中运行以下代码,尝试在同一 Azure 订阅中获取云服务的详细信息,并获取关于 Certificate is not associated with the subscription 的异常。
虽然,在订阅刀片下,在“管理证书”下,证书确实存在并获得了授权。
X509Store certStore = new X509Store(StoreName.My, storeLocation);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, prodThumbprint, false);
if (certCollection.Count > 0)
CredentialsProd = new CertificateCloudCredentials(DBConstants.AZURE_SUBSCRIPTION_ID_PROD, certCollection[0]);
using (var client = new ComputeManagementClient(Credentials))
{
var t = client.HostedServices.GetDetailedAsync(serviceName, CancellationToken);
}
例外:
ForbiddenError:服务器未能对请求进行身份验证。验证证书是否有效并且与此订阅相关联。