Hi ,
I'm using .Net 4.8 Version, all my connection string & secret Keys are stored in App.config. I want to make use of Azure App configuration in order to read the values from Azure rather than hardcode.
Thanks,
Hi ,
I'm using .Net 4.8 Version, all my connection string & secret Keys are stored in App.config. I want to make use of Azure App configuration in order to read the values from Azure rather than hardcode.
Thanks,
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted Jul 5, 2023, 7:00 AM EDT
Hi Shiva
To use Azure App Configuration to read values such as connection strings and secret keys instead of hardcoding them in your .NET 4.8 application's App.config, you can follow these steps:
Create an Azure App Configuration: First, you need to create an Azure App Configuration service in your Azure portal. This service will store the configuration settings you want to retrieve in your .NET application.
Install Azure.Extensions.AspNetCore.Configuration.AzureAppConfiguration Package: In your .NET 4.8 project, install the
Azure.Extensions.AspNetCore.Configuration.AzureAppConfigurationNuGet package. This package provides the necessary extension to read settings from Azure App Configuration.Update Program.cs: In the
Program.csfile of your .NET application, add the following code to set up the Azure App Configuration provider:using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration; using Microsoft.Extensions.DependencyInjection; class Program { static void Main(string[] args) { var builder = new ConfigurationBuilder(); var services = new ServiceCollection(); // Add Azure App Configuration as a configuration source services.AddAzureAppConfiguration(options => { options.Connect(""); }); // Build the configuration var config = builder.Build(); // Use the configuration as needed // For example, accessing connection string string connectionString = config.GetConnectionString("YourConnectionStringKey"); // Use the configuration in your application // ... } }Replace Connection Strings in App.config: Remove the connection strings and other sensitive information from your
App.configfile since you'll be reading them from Azure App Configuration.Set Up Access to Azure App Configuration: In the
options.Connect()method call, replacewith the actual connection string of your Azure App Configuration service. This will allow your application to access the configurations stored there.Secure Access to Azure App Configuration: Ensure that your application has the necessary permissions to access the Azure App Configuration service securely. You can use Managed Identity or a Service Principal for this purpose, depending on your security requirements.
Hope this helps
Deepak RawatRank #646 · 3.7K reputationPosted Jul 5, 2023, 7:30 AM EDT
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.AzureAppConfiguration;var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration(options => { options.Connect("") .Use("YourAppConfigLabel") .Select("YourAppConfigEnvironment"); }); var configuration = builder.Build();string connectionString = configuration.GetConnectionString("YourConnectionStringKey");