【问题标题】:Possible to update Azure Web App Setting with LinqPad?可以使用 LinqPad 更新 Azure Web 应用程序设置吗?
【发布时间】:2020-02-18 21:06:12
【问题描述】:

我想知道是否可以使用 LinqPad 应用程序更新 Azure Web 应用程序配置设置?网络应用中哪些地方需要更新的参考,请看下图。

我知道可以使用 LinqPad 更新网络设置(一位同事创建了脚本)。我有登录凭据 (Microsoft.Rest.Azure.Authentication.ApplicationTokenProvider) 和订阅 ID (Microsoft.Azure.Management.WebSites.WebSiteManagementClient)。然而,当尝试使用 WebApps(来自“Microsoft.Azure.Management.WebSites”程序集/命名空间)时,我不确定我应该使用什么,或者是否可以这样做。

【问题讨论】:

  • 嗨,我来这里是想看看问题是否可以按照下面的答案解决?

标签: azure azure-web-app-service linqpad application-settings


【解决方案1】:

是的,这是可能的。您可以先创建一个服务原理(使用azure cli 或azure portal)进行身份验证,然后安装此包Microsoft.Azure.Management.Fluent。

然后使用下面的代码在 Azure 门户中添加或更新应用程序设置:

public static void UpdateSetting(string key, string value)
{
    string tenantId = "xx";
    string clientSecret = "xx";
    string clientId = "xxx";
    string subscriptionId = "xx";

    //resource group name
    string rg_name = "xx";

    //azure web app name
    string app_name = "xxx";

    var azureCredentials = new AzureCredentials(new
      ServicePrincipalLoginInformation
    {
        ClientId = clientId,
        ClientSecret = clientSecret
    }, tenantId, AzureEnvironment.AzureGlobalCloud);


    var myazure = Azure
        .Configure()
        .Authenticate(azureCredentials)
        .WithSubscription(subscriptionId);

    var webapp = myazure.WebApps.GetByResourceGroup(rg_name, app_name);
    webapp.Update()
        .WithAppSetting(key, value)
        .Apply();                                                
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    相关资源
    最近更新 更多