Views: 571
Number of votes: 8
Average rating:

Playing with Episerver webconfig settings programmatically

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

Thanks and Regards

Ravindra S. Rathore

Oct 17, 2019

K Khan
(By K Khan , 10/18/2019 9:03:30 AM)

Wondering, what happened when you wrote something programmatically in web.config?

Ravindra S. Rathore
(By Ravindra S. Rathore, 10/19/2019 6:42:21 AM)

Hi K Khan,

It will write the entry and recycle the app pool.

(By valdis, 10/19/2019 11:49:24 AM)

I would not recommend to write anything back to web.config :)

Ravindra S. Rathore
(By Ravindra S. Rathore, 10/19/2019 12:15:30 PM)

Yes, true but we can use this class to read settings from web.config

Please login to comment.