image

Playing with Episerver webconfig settings programmatically

image By - Ravindra Rathore
17 Oct 2019

Hi Guys,

Sometimes we need to read, write or update some of the property from the Episerver web.config so Episerver provided a class called “EPiServerFrameworkSection“. By using this class we can achieve this.

I found this class very handy and I used this many times when I have to read, write and update the settings on web.config programmatically.

This exists in “EPiServer.Framework.Configuration” namespace.

Some Examples-

Reading providers from config-

                                            
ProviderSettingsCollection virtualRoles = EPiServerFrameworkSection.Instance.VirtualRoles.Providers;
ProviderSettingsCollection blobProviders = EPiServerFrameworkSection.Instance.Blob.Providers;

                                                

Reading connections string –


var ConnectionStrings = EPiServerFrameworkSection.Instance.CurrentConfiguration.ConnectionStrings;

Reading Appdata path-


string appData = EPiServerFrameworkSection.Instance.AppData.BasePath;


There are lots of other options as well that you can explore on your own. Here are some great documentation from Episerver

https://world.episerver.com/documentation/class-library/?documentId=cms/11/4E02FB31

https://world.episerver.com/documentation/class-library/?documentId=episerverframework/7/09b6aa52-2249-641a-ed99-d6ebe9afc589

Thanks for reading this blog post I hope it helps

Thanks and regards

Ravindra S. Rathore