Feature delegation of custom module in UI

I was at TechEd developers last week and one question that came up was what it takes for custom modules to show up in "Features Delegation" UI. I had image copyright walkthrough setup on the machine and in spite of having the custom schema xml and <section> entry in applicationHost.config, imageCopyright was not shown in "Features Delegation" UI. I did some more investigations on it and following is what it takes for UI to offer delegation to a custom module.

As feature delegation can be done at various levels, just having a new section doesn't allow UI to offer delegation for it. It requires one to extend admin UI tool. Go through image copyright walkthrough to see how to extend UI. Following methods need to be implemented in the UI module provider for feature delegation page to include your custom module as well.

  1. public bool SupportsDelegation - Feature delegation UI checks if the custom module provider supports delegation using this property. Abstract class ModuleProvider which is base class of all module providers returns false by default. If you dont override this property in your custom module provider, your feature wont show up in the "features delegation" list.
  2. public DelegationState GetChildDelegationState(string path) - Features delegation UI call this method to check the current delegation state of a module at a given path.
  3. public DelegationState[] GetSupportedChildDelegationStates(string path) - Features delegation UI calls this to get the supported delegation states. For configuration sections this would typically return Read Only, Read/Write, Remove delegation and Reset to inherited.
  4. public void SetChildDelegationState(string path, DelegationState delegationState) - This gets called when someone changes the delegation of the module in UI. delegationState is the new state which should be set at path 'path'.

Implementing all this for image copyright module is easy. Instead of deriving imageCopyrightUIProvider class from ModuleProvider, we can derive it from ConfigurationModuleProvider which has the above methods implemented in it. ConfigurationModuleProvider requires you to add a get property to your module provider to tell the name of the section which gets locked. For image copyright walkthrough following changes are required.

//
// Inherit from ConfigurationModuleProvider instead of ModuleProvider
//
class imageCopyrightUIProvider : ConfigurationModuleProvider

//
// Add ConfigurationSectionName getter to tell section name which gets locked
//
protected
override string ConfigurationSectionName
{
    get 
    {
        return "system.webServer/imageCopyright";
    }
}

Compile your module again, add to GAC and launch UI again. You should see imageCopyRight in your features delegation UI. I tried locking the section at server level by selecting "Read Only" from the available options and sure enough UI added the following to applicationHost.config which locked the section at machine level.

<location path="" overrideMode="Deny">
    <system.webServer>
        <imageCopyright />
    </system.webServer>
</location>

View the original post

No Comments