smithsson68@gmail.com
Jun 14, 2010
  5808
(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 CMS and weekly updates

Learn how reporting bugs in Optimizely CMS not only helps improve the platform but also benefits you and the entire user community.

Tomas Hensrud Gulla | Sep 12, 2024 | Syndicated blog

Introduce the ablility to select then delete items manually on FIND UI

In FIND 16.3.0 we introduce an ability to select items and delete them manually, it will helps you to delete unexpected items from the UI without a...

Manh Nguyen | Sep 12, 2024

The composable consulting model our industry needs

The architecture of a modern consulting business is ‘composable’. Certainly, we think of ourselves a composable consulting business and have done...

Mark Everard | Sep 12, 2024 | Syndicated blog

Keynote Summary from Opticon 2024, Stockholm

At Opticon in Stockholm, marking the 30th anniversary of Optimizely, the company celebrated significant achievements. These included surpassing $40...

Luc Gosso (MVP) | Sep 11, 2024 | Syndicated blog