我正在尝试使用 Azure 管理库 NuGet 包通过 ComputeManagementClient.UpgradeByNameAsync 升级部署。
我正在使用证书的指纹从证书存储加载它并创建我的凭据,但我的请求不断被拒绝,并显示以下消息:
The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
我已尽我所能来解决这个问题,但没有任何效果。
我已四重检查我的指纹是否正确,并且证书是否显示在 azure 的管理证书列表中。关于我可能出错的地方有什么想法吗?
最佳答案
public static CertificateCloudCredentials FromPublishSettingsFile(string path, string subscriptionId)
{
try
{
var profile = XDocument.Load(path);
var certificate = new X509Certificate2(
Convert.FromBase64String(profile.Descendants("PublishProfile").First()
.Attribute("ManagementCertificate").Value));
return new CertificateCloudCredentials(subscriptionId, certificate);
}
catch (Exception ex)
{
throw ex;
}
}
使用此代码块从发布设置文件创建一个CertificateCloudCredentials 类型的对象。成功创建对象后,使用以下代码块创建computeManagementClient。
var computeManagementClient = new ComputeManagementClient(creds);
虽然计算管理客户端仅接受 SubscriptionCloudCredentials,但 CertificateCloudCredentials 是兼容的并且将被接受。
关于Azure 管理库,证书被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22600905/