Create a new configuration

In this example, you create a page appearance configuration that stores page settings, such as fonts and colors.

To create the configuration, you perform the following:

  1. Create the configuration section class
    In the class you define the configuration properties that you need.
    Inherit from 
    ConfigSectionYou must use only primitive types for configuration properties. You can use NameValueCollection, but you cannot have more than one NameValueCollection property for a configuration element. To use a collection in the configuration class, you use ConfigElementDictionary. You can use complex properties with TypeConverter that serializes to a primitive type. To persist a property in the configuration file, you must add the ConfigurationProperty attribute.

    IMPORTANT: The NameValueCollection must be named Parameters.

    The following code creates the configuration section class:

    You represent the page appearance with a collection of fonts and a color. You define a property for controlling whether the appearance is valid only for remote connection. The NameValueCollection stores collection of properties that you define in the configuration provider.

  2. Create the configuration elements.

    To create the configuration elements that represent the font and the color, you inherit from ConfigElement. You must create a constructor with ConfigElement parameter that is the parent element. You use IsKey to define a key for the class.

    The following code creates the font and color elements:

  3. Register the new configuration
    You must register the configuration section class when the application starts - in the Global.asax or when developing a module - in the Initialize method of the module class.

    The following code snippet registers the configuration in the Global.asax file:

After you register the configuration, Sitefinity CMS creates a file PageAppearanceConfig.config that is stored in ~/App_Data/Sitefinity/Configuration and it allows you to modify it from the backend. To do this, navigate to Administration » Settings » Advanced.

Additional resources

EXTERNAL RESOURCES
MSDN: How to: Implement a Type Converter

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?