November Happy Hour will be moved to Thursday December 5th.

Ravindra S. Rathore
Oct 17, 2019
  2163
(8 votes)

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

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 and Regards

Ravindra S. Rathore

Oct 17, 2019

Comments

K Khan
K Khan Oct 18, 2019 07:03 AM

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

Ravindra S. Rathore
Ravindra S. Rathore Oct 19, 2019 04:42 AM

Hi K Khan,

It will write the entry and recycle the app pool.

valdis
valdis Oct 19, 2019 09:49 AM

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

Ravindra S. Rathore
Ravindra S. Rathore Oct 19, 2019 10:15 AM

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

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog