Azure管理客户端不返回任何资源组

时间:2019-04-11 01:06:28

标签: c# azure

我是天青。我正在尝试创建ResourceGroup,然后尝试部署VM。但是在访问资源组期间出现异常。

我正在遵循此处给出的MSDN示例:https://docs.microsoft.com/en-us/azure/virtual-machines/windows/csharp-template

我尝试了不同的订阅,但是没有运气。在网上找不到有关此问题的任何指针,否则我可能会错过。如果您能帮助我,请告诉我。

谢谢。

$(document).ready(function() {    
    $('html').animate({
        scrollTop: $(document).height()
    }, function(){
        var city = $('.pv-entity__location:first:last-child').text().trim()
        console.log(`Text: ${city} || "empty"}`)
    });

    //});
});

//异常详细信息。


//AppId,Key,TenetId are correct
var credentials = SdkContext.AzureCredentialsFactory
                .FromServicePrincipal(ApplicationID, Key, TenetID,
                    new AzureEnvironment()
                    {
                        AuthenticationEndpoint = @"https://login.windows.net/",
                        ManagementEndpoint = @"https://management.core.windows.net/",
                        ResourceManagerEndpoint = @"https://management.azure.com/",
                        GraphEndpoint = @"https://graph.windows.net/",
                    });

 var azure = Azure
                .Configure()
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .Authenticate(credentials)
                .WithSubscription(AzureProperties.SubscriptionId);

            var groupName = "MyresourceGroup1";
            var location = Region.USWest;

//Exception comes at here.
            var resourceGroup = azure.ResourceGroups.Define(groupName)
                .WithRegion(location)
                .Create();

1 个答案:

答案 0 :(得分:0)

我认为代码当前失败,因为您尚未为初始化的KeyVaultSuffix的{​​{1}}属性设置任何值。

是在查看您共享的错误信息的一种猜测,但是在查看了.NET的Azure管理库的相关源代码之后,我才这样说

(顺便说一句,任何人都可以做到。..这是link

AzureEnvrionment

如何修复

除非有充分的理由,否则我不会初始化 public async override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var adSettings = new ActiveDirectoryServiceSettings { AuthenticationEndpoint = new Uri(Environment.AuthenticationEndpoint), TokenAudience = new Uri(Environment.ManagementEndpoint), ValidateAuthority = true }; string url = request.RequestUri.ToString(); if (url.StartsWith(Environment.GraphEndpoint, StringComparison.OrdinalIgnoreCase)) { adSettings.TokenAudience = new Uri(Environment.GraphEndpoint); } string host = request.RequestUri.Host; // I guess this is where your code is failing currently. if (host.EndsWith(Environment.KeyVaultSuffix, StringComparison.OrdinalIgnoreCase)) { 对象,而是使用已经可用的值,因为这将确保所有必需的属性都具有正确的值。

示例:AzureEnvironment。在here中查找所有可能的值

在初始化AzureEnvironment的位置更改此代码

AzureEnvironment.AzureGlobalCloud

此代码

var credentials = SdkContext.AzureCredentialsFactory
            .FromServicePrincipal(ApplicationID, Key, TenetID,
                new AzureEnvironment()
                {
                    AuthenticationEndpoint = @"https://login.windows.net/",
                    ManagementEndpoint = @"https://management.core.windows.net/",
                    ResourceManagerEndpoint = @"https://management.azure.com/",
                    GraphEndpoint = @"https://graph.windows.net/",
                });

如果出于某些原因,可用环境值都不足够好,请确保初始化AzureEnvironment的所有必需属性