Search code examples
azure-sdk-.netazure-gov

Does Azure SDK 4 .NET support Azure gov?


Try to get Subscription's operations within Azure Gov, but the default api endpoint for Azure ManagementClient is the global one: https://management.azure.com/,

After I specified the endpoint of azure gov ( https://management.usgovcloudapi.net/) to the ManagementClient's constructor method

e.g var managementClient = new ManagementClient(credentials, new Uri("https://management.usgovcloudapi.net/") it returns api version missing.. and after I put a api-version as a suffix to the uri, it returns no subscription id found..

any one know it works with azure gov as well?

please anyone or any help.


Solution

  • Does Azure SDK 4 .NET support Azure gov?

    Yes, we could use the following SdkContext.AzureCredentialsFactory to choose the Azure environment. The following is the demo code, you could refer to.

    var tenantId = "tenant Id";
    var secretKey = "secret Key ";
    var clientId = "Application Id";
    var subscriptionId = "subscription Id";
    credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, secretKey, tenantId,AzureEnvironment.AzureUSGovernment);
    var resourceManagementClient = new ResourceManagementClient(credentials)
                {
                    SubscriptionId = subscriptionId 
                };