Can we set the Azure web app configuration settings from .net code.

lakshmi 491 Reputation points

Hi, We use a webchat system for both admin and user roles. Admins must possess specific privileges to modify the default settings in the Azure Web App Service configuration. Is it possible to update the app settings configuration using .NET code (version 6) and the using Bot Framework. User's image

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,474 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Konstantinos Passadis 16,561 Reputation points

    Hello @lakshmi !

    Of course you can i just cannot see where the Bot Framework adds

    You can do it by enabling the appropriate Azure SDK packages and take care Authentication .

    For example if you run your code via your Local Machine , a VM or anything else you may need a Managed Identity type of Authentication with permissions like Entra ID ;

    You can also use Rest API calls to perform the changes

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped! Regards

  2. SnehaAgrawal-MSFT 17,401 Reputation points Microsoft Employee

    You can update the app settings configuration of an Azure Web App using .NET code and the Bot Framework. You can use the Azure Management Libraries for .NET to programmatically manage your Azure resources, including your Web App. Here is an example of how you can update the app settings configuration of an Azure Web App using C# code:

    using Microsoft.Azure.Management.AppService.Fluent;
    using Microsoft.Azure.Management.AppService.Fluent.Models;
    using Microsoft.Azure.Management.ResourceManager.Fluent;
    using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
    using Microsoft.Rest;
    // Authenticate with Azure using a service principal
    var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
        clientId: "your-client-id",
        clientSecret: "your-client-secret",
        tenantId: "your-tenant-id",
        environment: AzureEnvironment.AzureGlobalCloud);
    // Get a reference to your Web App
    var webApp = await Azure
        .GetByResourceGroupAsync("your-resource-group-name", "your-web-app-name");
    // Update the app settings configuration
    var appSettings = new Dictionary<string, string>
        { "key1", "value1" },
        { "key2", "value2" }
    await webApp.Update()

    In this example, we first authenticate with Azure using a service principal. Then, we get a reference to our Web App using its resource group name and name. Finally, we update the app settings configuration of the Web App using the WithAppSettings method and apply the changes using the ApplyAsync method. You can integrate this code into your Bot Framework application to dynamically update the app settings configuration based on your logic. Let us know

    0 comments No comments