[英]How to get Azure Cloud Service details from App service via Code, .NET
Running the following code in Azure App service, which try to get details of a cloud service in the same Azure subscription, and get the exception about Certificate is is not associated with the subscription. 在Azure应用服务中运行以下代码,该代码尝试获取同一Azure订阅中的云服务的详细信息,并获取有关证书的异常与订阅未关联。
Although, under the subscription blade, under "Management certificates" the certificate does exists and authorized. 尽管在订阅刀片服务器下的“管理证书”下确实存在并授权了证书。
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);
}
The exception: 例外:
ForbiddenError: The server failed to authenticate the request.
ForbiddenError:服务器无法验证请求。 Verify that the certificate is valid and is associated with this subscription.
验证证书有效并与此预订关联。
To use a certificate that is uploaded to or imported into App Service, first make it accessible to your application code. 要使用上载到或导入到App Service中的证书,请首先使其可用于您的应用程序代码。 You do this with the WEBSITE_LOAD_CERTIFICATES app setting.
您可以使用WEBSITE_LOAD_CERTIFICATES应用设置进行此操作。 For more detail information, please refer to Use an SSL certificate in your application code in Azure App Service .
有关更多详细信息,请参考Azure App Service中的应用程序代码中的使用SSL证书 。
Add an app setting called WEBSITE_LOAD_CERTIFICATES and set its value to the thumbprint of the certificate.
添加一个名为WEBSITE_LOAD_CERTIFICATES的应用程序设置,并将其设置为证书的指纹。 To make multiple certificates accessible, use comma-separated thumbprint values.
要访问多个证书,请使用逗号分隔的指纹值。 To make all certificates accessible, set the value to *.
要使所有证书都可访问,请将值设置为*。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.