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 site settings is EPiServer.Configuration.Settings.Instance,
defined as:
C#
public static Settings Instance
To locate the settings for a specific site in episerver.config, scroll down to the
<EPiServer> section and find the <sites> element
collection. Accessing the settings through the use of the Instance property will list settings for the current site.
Here follows a sample of how to read and present site settings by using
EPiServer.Configuration.Settings.Instance.
Note that reading the EPiServer
CMS settings programmatically will slow the
website down.
Code-behind in SiteSettingsPage.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;
namespace CodeSamples
{
public partial class SiteSettingsPage : EPiServer.TemplatePage
{
protected void Page_Load(object sender, EventArgs e)
{
lblWasteBasket.Text = Settings.Instance.PageWastebasketId.ToString();
lblSiteURL.Text = Settings.Instance.SiteUrl.ToString();
lblUIUrl.Text = Settings.Instance.UIUrl.ToString();
string customSetting = System.Web.Configuration.WebConfigurationManager.AppSettings["myCustomSetting"];
}
}
}
Markup in SiteSettingsPage.aspx
XML
<table cellspacing="4" border="1">
<tr>
<td>WasteBasket ID</td>
<td><asp:label id="lblWasteBasket" runat="server" text="Label" /></td>
</tr>
<tr>
<td>The URL of the site</td>
<td><asp:label id="lblSiteURL" 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 the following:
WasteBasketID |
2 |
The URL of the site |
http://localhost:6666/EPiServerTest/ |
The UI URL |
http://localhost:6666/EpiServerTest/ui/ |
Do you find this information helpful? Please log in to provide feedback.