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

lakshmi 671 Reputation points
2024-01-18T17:57:22.0133333+00:00

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.
7,408 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Konstantinos Passadis 17,456 Reputation points MVP
    2024-01-18T18:25:10.2666667+00:00

    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 ;

    https://learn.microsoft.com/en-us/azure/azure-app-configuration/concept-enable-rbac

    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 20,856 Reputation points
    2024-01-24T07:22:55.0466667+00:00

    @lakshmi
    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
        .Configure()
        .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
        .Authenticate(credentials)
        .WithDefaultSubscription()
        .WebApps
        .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()
        .WithAppSettings(appSettings)
        .ApplyAsync();
    

    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