从代码更改 Azure 网站应用设置 [英] Change Azure website app settings from code

查看:16
本文介绍了从代码更改 Azure 网站应用设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从应用本身更改网站的应用设置?

Is it possible to change the app settings for a website from the app itself?

这不是日常操作,而是自助重新配置选项.非开发人员可以更改特定设置,这应该会导致重新启动,就像我可以在网站配置页面(应用设置部分)上手动执行一样

This is not meant to be an everyday operation, but a self-service reconfiguration option. A non-developer can change a specific setting, which should cause a restart, just like I can do manually on the website configuration page (app setting section)

推荐答案

您也可以使用 Azure Fluent Api.

You can also use the Azure Fluent Api.

using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;

...

public void UpdateSetting(string key, string value)
{
    string tenantId = "a5fd91ad-....-....-....-............";
    string clientSecret = "8a9mSPas....................................=";
    string clientId = "3030efa6-....-....-....-............";
    string subscriptionId = "a4a5aff6-....-....-....-............";

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

    var _azure = Azure
   .Configure()
   .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
   .Authenticate(azureCredentials)
   .WithSubscription(subscriptionId);

    var appResourceId = "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/sites/xxx"; //Get From WebApp -> Properties -> Resource ID

    var webapp = _azure.WebApps.GetById(appResourceId);

    //Set App Setting Key and Value
    webapp.Update()
        .WithAppSetting(key, value)
        .Apply();
}

这篇关于从代码更改 Azure 网站应用设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆