Try our conversational search powered by Generative AI!

smithsson68@gmail.com
Jun 14, 2010
  5730
(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 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

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024