Creating a Custom Site Definition Attribute

Author

Brandon Bruno

Published

Sometimes you may need to store a site-specific configuration setting. While there are plenty of ways to create and access configuration in Sitecore, storing a site-specific setting right on the site definition config might make the most sense (especially if it's a very high-level setting).

It may not always be best practice, but I've found it to make sense for a few recent projects. Accessing custom attributes on a site definition node is super-simple and requires no custom code.

A custom site definition attribute (simplified for clarity):

<site name="Blaze" 
	rootPath="/sitecore/content/sites/Blaze"
	startItem="/Home" 
	
	customSetting="my-setting-value"

/>

To access that value in code, use the Site.Properties collection:

string settingValue = Sitecore.Context.Site.Properties["customSetting"];