gpt4 book ai didi

azure - 调用 Azure WebSiteManagementClient GetConfiguration 时 AppSettings 未返回

转载 作者:行者123 更新时间:2023-12-03 03:07:21 27 4
gpt4 key购买 nike

使用 .NET Azure 包,我尝试读取我的 Azure 帐户上应用服务的 AppSettings。

当我尝试获取站点配置时,很多值都是null,包括 AppSettings 属性

我在控制台应用程序中使用以下软件包:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.Management.ResourceManager" version="1.1.3-preview" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Websites" version="1.6.0-preview" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.0" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.4-preview" targetFramework="net462" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net462" />
</packages>

下面的代码从应用服务读取配置

using Microsoft.Azure.Management.WebSites;
using Microsoft.Azure.Management.WebSites.Models;
using Microsoft.Rest.Azure.Authentication;
using System;
using System.Collections.Generic;
using System.Configuration;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string subscriptionId = ConfigurationManager.AppSettings["AzureSubscription"];
string tenantId = ConfigurationManager.AppSettings["AzureTenantId"];
string clientId = ConfigurationManager.AppSettings["ClientId"];
string clientSecret = ConfigurationManager.AppSettings["ClientSecret"];

var serviceCreds = ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret).Result;

WebSiteManagementClient webClient = new WebSiteManagementClient(serviceCreds);
webClient.SubscriptionId = subscriptionId;

string resourceGroup = ConfigurationManager.AppSettings["ResourceGroup"];
string appServiceName = ConfigurationManager.AppSettings["AppServiceName"];
string location = ConfigurationManager.AppSettings["AppLocation"];

SiteConfig siteConfig = webClient.WebApps.GetConfiguration(resourceGroup, appServiceName);

IList<NameValuePair> appSettings = siteConfig.AppSettings;
//appSettings is null, but shouldn't be
Console.Read();

}
}
}

我知道凭据是正确的,因为:

  • siteConfig 返回门户中正确的一些数据
  • 我可以使用以下代码更新应用程序设置:

    var settings = new StringDictionary
    {
    Location = location,
    Properties = new Dictionary<string, string>
    {
    { "Key", "a value" },
    },
    };

    webClient.WebApps.UpdateApplicationSettings(resourceGroup, appServiceName, settings);

更新:

我决定直接调用 REST API。出现同样的问题:

enter image description here

最佳答案

答案:

我不确定为什么应用程序设置没有作为 GetConfiguration 的一部分返回。

但是还有一个explicit有效的方法

StringDictionary appSettings = webClient.WebApps.ListApplicationSettings(resourceGroup, appServiceName);

关于azure - 调用 Azure WebSiteManagementClient GetConfiguration 时 AppSettings 未返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com