Hide menu Last updated: Mar 31 2014

EPiServer CMS settings are accessed 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:

C#
public static Settings Instance

Accessing the settings through the use of the Instance property will list settings for the application.

Here follows a sample of how to read and present application settings by using EPiServer.Configuration.Settings.Instance.

Note Reading the EPiServer CMS settings programmatically will slow the website down.

Code-behind in ApplicationSettingsPage.aspx.cs

C#
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

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

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

UrlRewriteExtension .htm
The UI URL ~/EpiServerTest/ui/

Comments