Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

smithsson68@gmail.com
Jun 14, 2010
  5732
(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
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog