Site-specific settings

Overview

Each Sitefinity CMS instance has a default configurations set. Each site that belongs to this instance can have its own, site-specific settings. To do this, you need to break the inheritance from the default configurations and create site-specific settings.

The default configurations are saved on the file system. They cannot be changed during runtime. Out of the default configurations, you can create site-specific settings. These settings are saved in the database. They can be changed runtime. Once you create site-specific configurations, they become settings.

PREREQUISITES: To create site-specific settings, your Sitefinity CMS instance must be in auto-storage mode of the configurations. For more information, see Auto-storage mode of configurations.

Site-specific settings and continuous delivery You create site-specific settings on your Production environment. The sites from a Sitefinity CMS multisite instance are considered content and are part of the database. The site-specific settings are bound to the database and are, by definition, application settings. If you have configured Sitefinity CMS in continuous delivery, site-specific settings cannot be part of the continuous delivery process, because they belong to the database.

Unless a site is configured by deployment, you create and modify its settings on the Production environment.

Configure by deployment

If you have set your sites to be configured by deployment packages via the continuous delivery process, you cannot create site-specific settings on the next environment.
For more information, see Deployment mode of websites.

IMPORTANT: When using config transformations from web.config appSettings section, you lose the ability to edit those configurations per site.

Limitations

  • When you create site-specific settings, you can expect them to apply only to newly developed functionality. Existing customizations and out-of-the-box features do not respect and apply the new site settings automatically.
  • The out-of-the-box Sitefinity configurations do not support AllowPerSitesetting, if enabled.

Exceptions

The following properties cannot be made site-specific:

  • ConfigElement properties marked as key properties.
    For example, [ConfigurationProperty("background", IsKey = true)] cannot persist site-specific values.
  • SiteSettings config
    SiteSettings config applies to all sites.
  • Sitemap configs cannot have site-specific properties defined. 
    Sitemap config has its own internal logic of handling different site settings.
  • ConfigElement parameters collection of type NameValueCollection are not supported.

Procedure

To create site-specific settings, on your production environment, perform the following:

  1. Navigate to Administration» Settings » Advanced.
  2. Locate the property that you want to make site-specific.
    This property will have different values for the site that you choose.
  3. Click its question mark.
  4. Copy the value that is displayed in the tooltip.
  5. In the tree on the right, expand SiteSettingsConfig and click SiteSpecificProperties.
  6. Click Create new.
  7. In Path, enter the copied value.
  8. Save your changes.
  9. Restart your application.
  10. Navigate again to Administration » Settings » Advanced.
  11. Locate the property that you want to make site-specific.
  12. Use the site selector to choose the site for which you want to have a different value.
  13. Click Break inheritance.
  14. Enter the new value of the property and save your changes.# Site-specific settings

Site-specific settings API# Site-specific settings

RECOMMENDATION: When reading site-specific settings, we recommend using Config.Get<DummyConfig>(). It will respect the current site context and load any site-specific values for it. It also caches the configuration and increases performance. We do not recommend using ConfigManager.GetManager().GetSection<DummyConfig>(), because it does not load site-specific values and does not cache the loaded configurations.

To work with site-specific settings with the native API, use the following code sample:

C#
[Test]
[Category(TestCategories.Core)]
[IgnoreWhenDbConfig("Per site configuration only allowed in Auto mode")]
[ExpectedNotSupportedExceptionWhenReadOnly]
public void ConfigPersistencePerSiteTests_NativeApi_WorksAsExpected()
{
   // StringProp is site specific and StringProp2 is not site specific

   // updates the all sites values of site specific properties
   Config.UpdateSection<DummyConfig>(s =>
   {
       s.StringProp = "AllSites1";
       s.StringProp2 = "AllSites2";
   });

   // gets the all sites values
   var dummy = Config.Get<DummyConfig>();
   Assert.AreEqual("AllSites1", dummy.StringProp);
   Assert.AreEqual("AllSites2", dummy.StringProp2);

   // enters a region where site specific config operations will occur
   using (new ConfigSiteContextRegion(SystemManager.CurrentContext.CurrentSite.Id))
   {
       // updates the value for the current site only for site specific properties
       // other properties will be ignored
       Config.UpdateSection<DummyConfig>(s =>
       {
           // current config element must be marked as persisting site specific values if not already
           // keep in mind that all site specific props for the ConfigElement will start persisting site specific values
           // even if they are not changed in the code here, they will get those from all sites values
           // ex. if there is StringProp3 that is also site specific it will also start persisting its all sites value
           // as site specific as well for current site
           s.PersistsSiteSpecificValues = true;
           s.StringProp = "SiteSpecific";

           // this value will not be persisted as the property is not site specific
           s.StringProp2 = "SiteSpecific_WillBeIgnored";
       });

       // gets the values for the current site for all site specific properties
       // other properties load their all sites values
       var siteSpecificDummy = Config.Get<DummyConfig>();
       Assert.AreEqual("SiteSpecific", siteSpecificDummy.StringProp);
       Assert.AreEqual("AllSites2", siteSpecificDummy.StringProp2);

       Config.UpdateSection<DummyConfig>(s =>
       {
           // removes all site specific values if any and the element will start inheriting again from all sites values for current site
           s.PersistsSiteSpecificValues = false;
       });

       siteSpecificDummy = Config.Get<DummyConfig>();
       Assert.AreEqual("AllSites1", siteSpecificDummy.StringProp);
       Assert.AreEqual("AllSites2", siteSpecificDummy.StringProp2);

       Config.UpdateSection<DummyConfig>(s =>
       {
           s.PersistsSiteSpecificValues = true;
           s.StringProp = "SiteSpecific";
       });
   }

   // ConfigManager API returns all sites value unless used in ConfigSiteContextRegion
   // It also does not cache the configuration object so it is not recommended for general use in custom code when reading values
   var valueFromConfigManagerAPI = ConfigManager.GetManager().GetSection<DummyConfig>().StringProp;
   Assert.AreEqual("AllSites1", valueFromConfigManagerAPI);
   using (new ConfigSiteContextRegion(SystemManager.CurrentContext.CurrentSite.Id))
   {
       valueFromConfigManagerAPI = ConfigManager.GetManager().GetSection<DummyConfig>().StringProp;
       Assert.AreEqual("SiteSpecific", valueFromConfigManagerAPI);
   }

   // Config API returns current site context values and caches the configuration
   // This is the recommended API to use in custom code when reading configuration values
   var valueFromConfigAPI = Config.Get<DummyConfig>().StringProp;
   Assert.AreEqual("SiteSpecific", valueFromConfigAPI);
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.