0

I want to use an Azure App Configuration store in a .Net Framework MVC web app. I have added references to the Microsoft.Extensions.Configuration.* assemblies. The goal is that my existing code which makes calls to ConfigurationManager.AppSettings["key"] should continue to work and simply retrieve values from Azure when they are available.

I have registered a new configBuilder in web.config, as such:

<add name="MyConfigStore" mode="Greedy" connectionString="xxx" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />

This works at runtime. However, during app initialization, in Startup.cs or Global.asax or when my DI container is built, the Azure configuration values are not found. It seems the Azure configBuilder is not yet registered. If I explicitly retrieve values from Azure, it works. If I simply call ConfigurationManager.AppSettings, it does not work.

IConfigurationRoot configuration = new ConfigurationBuilder()
    .AddAzureAppConfiguration(options =>
    {
        options.Connect(ConfigurationManager.AppSettings["AzureConfigConnString"])
            .UseFeatureFlags();
    }).Build();

//THIS WORKS
var someValue = configuration["key"];

//THIS DOES NOT WORK
someValue = ConfigurationManager.AppSettings["key"];

How can I register the Azure configBuilder so that it is used during Startup? All of the examples seem to be for .Net Core and they use CreateHostBuilder() which doesn't exist in my project.

betitall
  • 807
  • 2
  • 8
  • 19

1 Answers1

1

Answering my own question. The problem was that I needed a reference to:

Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration

not

Microsoft.Extensions.Configuration.AzureAppConfiguration.

I also needed a configBuilders attribute on the AppSettings node in web.config. After this, the startup code is not necessary.

betitall
  • 807
  • 2
  • 8
  • 19
  • Would you mind providing me with more details on how to do this I am fairly new to this. And how to use ConfigurationBuilder? – Uncharted Aug 02 '23 at 19:26