无法使用Microsoft.Azure.Management.ResourceManager.Fluent命名空间中的ResourceManagementClient类发现Azure资源

问题描述 投票:1回答:1
  1. [我正在尝试使用Microsoft.Azure.Management.ResourceManager.Fluent命名空间下.NET SDK类ResourceManagementClient中的以下代码片段来发现Azure政府资源。

    new ResourceManagementClient(creds).Resources.ListAsync()

  2. 虽然发现我遇到错误,因为找不到'subscription'。'

  3. 当我们尝试使用相同的代码在Azure公共环境上发现资源时,这工作得很好。] >>

  4. Azure政府的.NET SDK是否存在问题?还是因为Azure资源图服务不适用于Azure政府服务?

    我正在尝试使用Microsoft.Azure.Management.ResourceManager.Fluent命名空间new .NET SDK类ResourceManagementClient下的以下代码片段发现Azure政府资源。] >> [[

    您需要确保像这样为AzureEnvironment.AzureUSGovernment(下面的第2行)指定AzureCredentials

    var servicePrincipal = new ServicePrincipalLoginInformation { ClientId = "<your-client-id>", ClientSecret = "<your-client-secret" }; var creds = new AzureCredentials(servicePrincipal, tenantId: "<your-tenant-id>", AzureEnvironment.AzureUSGovernment); var azure = Azure.Configure().Authenticate(creds).WithDefaultSubscription(); var rgs = await azure.ResourceGroups.ListAsync();

azure azure-resource-manager azure-gov
1个回答
0
投票
您需要确保像这样为AzureEnvironment.AzureUSGovernment(下面的第2行)指定AzureCredentials

var servicePrincipal = new ServicePrincipalLoginInformation { ClientId = "<your-client-id>", ClientSecret = "<your-client-secret" }; var creds = new AzureCredentials(servicePrincipal, tenantId: "<your-tenant-id>", AzureEnvironment.AzureUSGovernment); var azure = Azure.Configure().Authenticate(creds).WithDefaultSubscription(); var rgs = await azure.ResourceGroups.ListAsync();

© www.soinside.com 2019 - 2024. All rights reserved.