简体   繁体   English

如何通过Code,.NET从App Service获取Azure Cloud Service详细信息

[英]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. 验证证书有效并与此预订关联。

The certificate in the subscription: 订阅中的证书: 在此处输入图片说明

The certificate in the App service App服务中的证书 在此处输入图片说明

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.

相关问题 如何从Azure云应用服务获取用户IP - How to get users IP from Azure cloud app service 如何从Azure Cloud Service的代码中获取服务名称? - How can I get the service name from code for a Azure Cloud Service? 通过.NET Azure SDK扩展云服务实例数量? - Scale Cloud Service Instance Count via .NET Azure SDK? 如何从 MSTest c# 代码中获取我的 Azure 应用服务的 accessToken - How to get accessToken to my Azure App Service from inside MSTest c# code 使用.NET C#从azure云服务读取配置设置 - Read configuration settings from azure cloud service with .NET C# Azure Cloud Service Classic with .NET Standard目标 - Azure Cloud Service Classic with .NET Standard target .NET Core 2.2:如何在 Azure 应用服务中从 Azure AD 自动填充用户列表? - .NET Core 2.2 : How to auto-populate list of users from Azure AD in Azure app service.? 如何获得使用ChromeDriver在Azure云服务中工作的C#azure服务 - How to get a C# azure service that uses ChromeDriver to work in an Azure Cloud Service 通过前端应用程序和postman / curl从Azure App Service中发布的.net core api获取不同的响应 - Gettting different responses from .net core api published in Azure App Service via the front-end app and postman/curl Azure应用服务无法从Azure IoT中心获取数据 - Azure App Service can not get data from Azure IoT Hub
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM