How To Add Custom Settings / App Settings In Sitecore
Wed 25 May, 2016 / By Jon D Jones
When building a website you will inevitably need to store configuration data somewhere. In today's post, I'm going to cover the options available to you when you use Sitecore.
Web.ConfigAs Sitecore is a .NET application you can always use the app settings section in your web.config.
<appSettings> <add key="SettingName" value="true" /> </appSettings>Which you can then access in code like this:
var value = ConfigurationManager.AppSettings["SettingName"];It's generally advised to try and keep your web.config as mean and lean as possible. If you want to upgrade your Sitecore, then you have to merge manually your web.config.
SiteCore SettingSitecore also provides an easy API to write your own APP settings file. This can be really useful if you want to deploy your site in different environments. To create your own Sitecore App settings file, first, create a new file in \App_Config\Include. You can call it whatever you like. I normally use ProjectName.Settings.config. In the file you can add in custom settings by using the following convention:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> <sitecore> <settings> <setting name="SettingName" value="true"/> </settings> </sitecore> </configuration>We can access these settings like this:
var value = Sitecore.Configuration.Settings.GetSetting("SettingName")If you have any issue with your settings, you can always check Make sure the Sitecore config page to make sure Sitecore knows about your setting. To access use the following in your web browser, www.website.com/sitecore/admin/showconfig.aspx. If you want to you can also use the Sitecore API to get access to normal App settings by using the following snippet: