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

smithsson68@gmail.com
Jun 14, 2010
  5837
(0 votes)

Updating configuration from code in CMS 6 onwards

With the introduction of the EPiServer Framework in EPiServer CMS 6, there are potentially multiple places in the EPiServer codebase that can update configuration from code. As the configuration is also often cached in memory, this can cause problems when trying to update it, as the cache may be out of date which will cause an exception to be thrown on saving.

To alleviate this problem a new API was introduced.

EPiServer.Framework.Configuration.GlobalConfigurationManager

This class contains two public members:

public static void Save(System.Configuration.Configuration configuration, RestartMode restartMode)

This allows you to save the configuration and specify what should happen in terms of restarting the web application. RestartMode is defined as follows:

public enum RestartMode
{
    None, // Don't restart the app (rely on default behavior)
    ThisApplicationOnly, // Restart this web only
    AllApplications // Restart all web apps that share same config
}

RestartMode is required because configuration is divided into several files. If the configuration changed is hosted in web.config then the normal ASP.NET behavior defined will occur regardless of what RestartMode value is passed. This is also the case if the configuration changed is hosted in another file but it's section handler in web.config has the restartOnExternalChanges attribute set to true.

public static event EventHandler ConfigurationSaved;

This event should be subscribed to by code that holds a cached version of the configuration. When the event is fired, your code should re-read the configuration from disk.

This API applies to all EPiServer products that ship with the EPiServer Framework.

Jun 14, 2010

Comments

Sep 21, 2010 10:33 AM

Nice post Paul - but I still 'really really' dislike EPiServer's functionality that allows it to update its own configuration files. It makes configuration management / source control and deployments unnecessarily complicated.

I would really love to see any EpiServer UI which allows an update to a configuration element completely 'obliterated' :)

IMHO, any configuration change that requires an application restart should be the responsibility of a system administrator or developer (working on the server itself) not the application itself. If the change doesn't require an application restart then why store it as a configuration element - persisting these values in the database would make more much sense and really help with configuration versioning.


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