Kentico CMS 6.0 Developer's Guide

Registering custom classes via the web.config

Registering custom classes via the web.config

Previous topic Next topic Mail us feedback on this topic!  

Registering custom classes via the web.config

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

The web.config of your Kentico CMS application may be used to map providers and helpers to custom classes that are included in your web project, i.e. either in a separate assembly or under the App_Code folder. To do this, please follow the steps described below:

 

1. Edit your web.config file and add the following into the <configSections> element:

 

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
 <configSections>

 
 ...
 

<!-- Extensibility BEGIN -->
 <section name="cms.extensibility" type="CMS.SettingsProvider.CMSExtensibilitySection" />
<!-- Extensibility END -->

 
 </configSections>
...

 

This defines a new extensibility section, where you can register custom providers and helpers.

 

2. Next, create the actual <cms.extensibility> section under the <configuration> node and add any necessary providers or helpers into the appropriate sub‑sections:

 

...

 

<!-- Extensibility BEGIN -->
<cms.extensibility>
 <providers>
   <add name="EmailProvider" assembly="App_Code" type="CustomEmailProvider" />
   <add name="SiteInfoProvider" assembly="App_Code" type="CustomSiteInfoProvider" />
   <add name="ForumPostInfoProvider" assembly="CMS.CustomProviders"
  type="CMS.CustomProviders.CustomForumPostInfoProvider" />
   ...
 </providers>
 <helpers>
   <add name="CacheHelper" assembly="App_Code" type="CustomCacheHelper" />
   ...
 </helpers>
</cms.extensibility>
<!-- Extensibility END -->

 

...

</configuration>

 

As you can see, each custom class is assigned to a provider or helper through its own <add> element with the following attributes:

 

name - must match the name of the provider/helper class that you wish to customize (without the extension).

assembly - specifies the assembly where the custom class is defined. Set the value to App_Code for classes located in this folder (even on web application installations, where the actual name of the folder is Old_App_Code).

type - used to specify the name of the custom class. If your custom class is in the App_Code folder, the value of this attribute will be passed in the ClassName property of the ClassEventArgs parameter, which is available for the onGetCustomClass event handler (as can be seen in step 3 of the Customizing providers from the App_Code folder topic).