API to add properties to Azure Webapp Application settings

半世苍凉 提交于 2019-12-02 00:24:34

问题


I have one web app running on a Azure appservice plan. The web app has a lot of settings defined in Application settings of the Web App. Now I want to replicate that web app with all its Application settings. I got the REST API to list down all the settings available for any web app (/api/settings). Although there is a POST call to add/update the settings , But it is not updating Application settings.

Is there any REST API to add/update the Application settings of Azure web app ?

Thanks, Abhiram


回答1:


Is there any REST API to add/update the Application settings of Azure web app ?

Yes, we could update the application setting with the following Update Application Settings REST API

Put https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resource group}/providers/Microsoft.Web/sites/{WebAppName}/config/appsettings?api-version=2016-08-01

Body

{
  "id": "subscriptions/{subscriptionId}/resourceGroups/{resource group}/providers/Microsoft.Web/sites/{WebAppName}/config/appsettings",
  "name": "appsettings",
  "type": "Microsoft.Web/sites/config",
  "location": "South Central US",
  "tags": {
    "hidden-related:/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Web/serverfarms/tomfreePlan": "empty"
  },
  "properties": {
    "WEBSITE_NODE_DEFAULT_VERSION": "6.9.1",
    "Test1": "testValue1" //Added value
  }
}

Note: we could use the following List Application Settings REST API post way to list the appsetting body.

 Post https://management.azure.com/subscriptions/{subscription}/resourceGroups/CXP-{resourceGroup}/providers/Microsoft.Web/sites/{WebAppName}/config/appsettings/list?api-version=2016-08-01



回答2:


To my knowledge, there is not. But have you considered scripting your Web App settings with an ARM template? This is exactly the kind of thing that ARM templates are intended for.

An example of the properties section of a Web App's ARM template that lets you script appSettings and connectionStrings is listed below:

"properties": {
    "name": "YourWebAppsName",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', YourAppServicePlanName)]",
    "siteConfig": {
        "appSettings": [
            {
              "name": "someAppSettingKey",
              "value": "someAppSettingValue"
            },
            {
              "name": "someOtherAppSettingKey",
              "value": "someOtherAppSettingValue"
            }
        ],
        "connectionStrings": [
            {
              "name": "defautlConnection",
              "connectionString": "YourConnectionString",
              "type": "2"
            },
        ]
    }

When you deploy an ARM template, Azure will ensure that the target resource's settings match what's specified in your template.

Visual Studio has a project type for developing and deploying these. It's the Azure Resource Group project type located under the Cloud node in the project templates.

As an added bonus, you can check these ARM templates into source control alongside your code.



来源:https://stackoverflow.com/questions/47749976/api-to-add-properties-to-azure-webapp-application-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!