Area: Optimizely CMS
Applies to versions: 10 and higher
Other versions:

Reading application settings programmatically

Recommended reading 

You can access Optimizely CMS settings through the use of a configuration class. All settings are typed members of this class, which gives the added benefit of being able to access all settings through Intellisense. The class responsible for serving application settings is EPiServer.Configuration.Settings.Instance, defined as:

public static Settings Instance

Accessing the settings through the use of the Instance property lists settings for the application.

The following example shows how to read and present application settings by using EPiServer.Configuration.Settings.Instance.

Note: Reading the Optimizely CMS settings programmatically slows down the website.

Code-behind in ApplicationSettingsPage.aspx.cs

using System;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Web.WebControls;

using EPiServer.Configuration;
using EPiServer.Web;

namespace CodeSamples
  public partial class ApplicationSettingsPage : EPiServer.TemplatePage
    protected void Page_Load(object sender, EventArgs e)
      lblUrlRewriteExtension.Text = Settings.Instance.UrlRewriteExtension;
      lblUIUrl.Text = Settings.Instance.UIUrl.ToString();

      // To read custom settings from the <appSettings> block in web.config
      // use code similar to:
      string customSetting = System.Web.Configuration.WebConfigurationManager.AppSettings["myCustomSetting"];

Markup in ApplicationSettingsPage.aspx

<table cellspacing="4" border="1">
    <td><asp:label id="lblUrlRewriteExtension" runat="server" text="Label" /></td>
    <td>The UI URL</td>
    <td><asp:Label id="lblUIUrl" runat="server" /></td>

The output from this code should resemble something like the following (depending on the actual configuration):

UrlRewriteExtension .htm
The UI URL ~/EpiServerTest/ui/
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 26, 2016

Recommended reading