ProviderFeature Class

Definition

Provides the base class for module providers.

public ref class ProviderFeature abstract
public abstract class ProviderFeature
type ProviderFeature = class
Public MustInherit Class ProviderFeature
Inheritance
ProviderFeature

Examples

The following example adds a provider (.NET Site Map) derived from a SiteMapProvider object. You will need the following four classes as part of your project.

SiteMapProviderConfigurationFeature

using System;
using Microsoft.Web.Management.Client.Extensions;
using Microsoft.Web.Management.Client;

namespace ProviderConfigurer {

    public class SiteMapProviderConfigurationFeature : ProviderFeature
    {
        public SiteMapProviderConfigurationFeature()
        {
            _selectedProvider = FeatureName;
        }

        public SiteMapProviderConfigurationFeature(string selectedProvider)
        {
            _selectedProvider = selectedProvider;
        }

        private string _selectedProvider;
        // The name that will show up in drop down on "Providers" page.
        public override string  FeatureName
        {
            get { return ".NET Site Map"; }
        }
        // The site map provider base type. The provider that is
        // configured will derive from this base type.
        public override string  ProviderBaseType
        {
            get { return "System.Web.SiteMapProvider"; }
        }
        // The siteMap providers collection is a collection inside a <providers> tag.
        public override string  ProviderCollectionPropertyName
        {
            get { return "providers"; }
        }

        // Each provider can be configured with these attributes.
        public override string[]  ProviderConfigurationSettingNames
        {
            get {
                return new string[] {"siteMapFile", 
                                     "description",
                                     "connectionStringName"};
            }
        }
        // The section for the siteMap element.
        public override string  SectionName
        {
            get { return "system.web/siteMap"; }
        }
        // The currently selected provider. 
        public override string SelectedProvider 
        {
            get {
                if (_selectedProvider == null)
                {
                    return String.Empty;
                }
                return _selectedProvider; }
        }
        // The name of the attribute that specifies the currently selected provider.
        public override string  SelectedProviderPropertyName
        {
            get {
                return "defaultProvider"; }
        }
        // Initializes the settings for the provider.
        public override ProviderConfigurationSettings Settings
        {
            get {return new SiteMapProviderConfigurationSettings();}
        }
    }
}

SiteMapProviderConfigurationFeatureModule

using System;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Server;
using System.Diagnostics;
using Microsoft.Web.Management.Client.Extensions;

namespace ProviderConfigurer {
    class SiteMapProviderConfigurationFeatureModule : Module{
        protected override void Initialize(
            IServiceProvider serviceProvider, ModuleInfo moduleInfo)
        {
            base.Initialize(serviceProvider, moduleInfo);

            Connection connection = (Connection)serviceProvider.GetService(
                typeof(Connection));
            Debug.Assert(connection != null);

            // Register the extensibility features with the extensibility manager
            IExtensibilityManager extensibilityManager = 
                (IExtensibilityManager)serviceProvider.GetService(
                typeof(IExtensibilityManager));
            Debug.Assert(extensibilityManager != null);

            if (extensibilityManager != null) {
                // Provider configuration
                SiteMapProviderConfigurationFeature siteMapProviderConfigurationFeature
                    = new SiteMapProviderConfigurationFeature();
                extensibilityManager.RegisterExtension(typeof(ProviderFeature),
                    siteMapProviderConfigurationFeature);
            }
        }

        protected override bool IsPageEnabled(ModulePageInfo pageInfo)
        {
            return true;
        }
    }
}

SiteMapProviderConfigurationFeatureModuleProvider

using System;
using Microsoft.Web.Management.Server;

namespace ProviderConfigurer {
    class SiteMapProviderConfigurationFeatureModuleProvider : ModuleProvider {
        public override Type ServiceType {
            get { return null; }
        }

        public override ModuleDefinition GetModuleDefinition(IManagementContext context) {
            return new ModuleDefinition(Name, typeof(
                SiteMapProviderConfigurationFeatureModule).AssemblyQualifiedName);

        }

        public override bool SupportsScope(ManagementScope scope) {
            return true;
        }
    }
}

SiteMapProviderConfigurationSettings

using System;
using System.Collections;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.AspNet;

namespace ProviderConfigurer
{
    public class SiteMapProviderConfigurationSettings : ProviderConfigurationSettings
    {
        Hashtable _settings;

        public SiteMapProviderConfigurationSettings()
        {
            _settings = new Hashtable();
        }

        public string SiteMapFile
        {
            get
            {
                if (_settings["siteMapFile"] != null)
                {
                    return (string)_settings["siteMapFile"];
                }
                return String.Empty;
            }
            set
            {
                _settings["siteMapFile"] = value;
            }
        }

        // overrides the abstract Settings property.
        protected override System.Collections.IDictionary Settings
        {
            get
            {
                return (IDictionary)_settings;
            }
        }

        // Overrides the abstract Validate method.
        public override bool Validate(out string message)
        {
            // Perform a validation check. If the key pairs collection
            // contains more than three pairs, pass a return value of 
            // false and a failure message.
            if (_settings.Count < 4)
            {
                message = "Validation succesful";
                return true;
            }
            else
            {
                message = "Validation failed - too many key value pairs";
                return false;
            }
        }
    }
}

Remarks

Modules that must configure providers have a feature that derives from this class. You can use this class to implement your own custom provider.

Once configured, the derived class will appear in the Feature drop-down box on the Providers page. The FeatureName property value will appear along with the predefined providers .NET Roles, .NET Users, and .NET Profile.

You can use the user interface (UI) in IIS Manager to add, edit, rename, or remove providers. Modifying a provider will result in a change to the Web.config file (located in the .NET Framework version 2.0 folder).

When you use this extensibility feature, you must also write a <xref:System.Web.Management.Client.Module> object and a ModuleProvider object to register the ProviderFeature class with the extensibility manager. The example below displays the coding for these three classes along with a ProviderConfigurationSettings class needed to establish the configuration setting for the provider.

Notes to Implementers

When you inherit from the ProviderFeature class, you must override the following members:

Constructors

ProviderFeature()

Initializes a new instance of the ProviderFeature class.

Properties

ConnectionStringAttributeName

Gets the name of the connection string to the provider database.

ConnectionStringRequired

Gets a value indicating whether a connection string is required to access the database.

FeatureName

When overridden in a derived class, gets the name of the feature for the provider.

ProviderBaseType

When overridden in a derived class, gets the type of provider.

ProviderCollectionPropertyName

When overridden in a derived class, gets the name of the provider collection.

ProviderConfigurationSettingNames

When overridden in a derived class, gets a collection with the setting names for the provider.

SectionName

When overridden in a derived class, gets the configuration section that set up the provider.

SelectedProvider

When overridden in a derived class, gets the name of the selected provider.

SelectedProviderPropertyName

When overridden in a derived class, gets the name of the attribute that specifies the currently selected provider.

Settings

When overridden in a derived class, gets the configuration settings for the provider.

Applies to