|
||
You can register custom providers and helpers through your application's web.config file. This is done by mapping provider objects to the appropriate custom classes. Registering providers in the web.config allows you to switch between different providers (custom or default) without having to edit the application code
Note: If you do not need your provider customizations to be adjustable through the web.config file, it is more efficient to register custom providers directly through the API in the App_Code folder (as described in Registering providers in App_Code).
1. Edit your web.config file and add the following section into the <configSections> element:
<?xml version="1.0"?>
|
This defines the cms.extensibility web.config section where you can register custom providers and helpers.
2. Create the actual <cms.extensibility> section directly under the root level of the web.config.
3. Assign your custom classes to providers or helpers via <add> elements 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 your custom class is located. Set the value to App_Code for classes placed in the App_Code folder (even on web application installations, where the actual name of the folder is Old_App_Code).
•type - specifies the name of your custom provider class (including namespaces).
oIf the class is in the App_Code folder, the system triggers the OnGetCustomClass event when requesting the provider class. The type value is passed on through the ClassName property of the event's ClassEventArgs parameter. When writing the event's handler, use the value to identify and load an instance of the appropriate custom provider class.
You need to categorize the <add> elements under <providers> or <helpers> sub-sections based on the type of the customized class.
<configuration> ...
... </configuration> |
In the case of custom providers placed in a separate assembly, the registration is now complete.
When using the web.config to register custom providers defined in the App_Code folder, you also need to ensure that the system can load the classes.
Example:
[C#]
using System; |
When the system requests an App_Code provider class registered through the cms.extensibility section of the web.config, the OnGetCustomClass event is triggered and the handler method returns an instance of the appropriate class.