Azure App Configuration with .NET Full Framework
By rickvdbosch
- 2 minutes read - 390 wordsThis post on using App Configuration using .NET Full Framework was based on a contribution by Steven Hack.
My last post Azure App Configuration: an introduction received a lot of good feedback. And one of those pieces of feedback was a question if it’s also possible to use App Configuration if you’re using Full Framework.
The short answer: yes, this is possible!
For the slightly longer answer: keep reading 🤓
Requirements ✔
There are a couple of things you need to keep into account if you want to use App Configuration in .NET FF. This is a list of things that had to be in place to be able to get App Configuration working with FF:
- .NET 4.7.1 or higher
- HttpRuntime target framework 4.6.1
- NuGet: System.Configuration.ConfigurationManager
- NuGet: Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration
Configuration 🏷
To be able to use App Configuration in .NET FF, you need to add it as a configuration builder. You can do so in the web.config
:
<configuration>
<configSections>
<section name="configBuilders"
type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
restartOnExternalChanges="false"
requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<!-- Use the endpoint if you want to use Managed Identities.
The connection string parameter is the old conventional way.
The latest version of the NuGet package does not support connection string anymore.
-->
<add name="AppConfigStore"
mode="Greedy"
endpoint="<YOUR_ENDPOINT>"
connectionString="<YOUR_CONNECTIONSTRING>"
type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</builders>
</configBuilders>
<appSettings configBuilders="AppConfigStore">
<add key="Setting1" value="local" />
</appSettings>
...
</configuration>
Using it 🧰
With all the plumbing out of the way, we can start using App Configuration. Look closely, since this next section contains all the code you need to get it up & running. Be sure not to miss anything!
This example reads the setting with name Setting1:
var setting = ConfigurationManager.AppSettings["Setting1"];
As a result, if the setting with name ‘Setting1’ is in App Configuration, it will take that one. If it’s not there but is in the Application Settings of the Azure App Service, that’s the value that will be used. And if that is not available, but there is a setting with that name in the appsettings.json
file, that will be the provided value.
You should be good to go!
Resources 🔗
Thanks again to Steven Hack for providing the example. His solution was based on the article Create a .NET Framework app with Azure App Configuration.
If you have any questions, don’t hesitate to contact me. Hope this helps!