Compartilhar via


ProviderFeature Classe

Definição

Fornece a classe base para provedores de módulo.

public ref class ProviderFeature abstract
public abstract class ProviderFeature
type ProviderFeature = class
Public MustInherit Class ProviderFeature
Herança
ProviderFeature

Exemplos

O exemplo a seguir adiciona um provedor (Mapa do Site do .NET) derivado de um SiteMapProvider objeto . Você precisará das quatro classes a seguir como parte do projeto.

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;
            }
        }
    }
}

Comentários

Os módulos que devem configurar provedores têm um recurso derivado dessa classe. Você pode usar essa classe para implementar seu próprio provedor personalizado.

Depois de configurada, a classe derivada aparecerá na caixa suspensa Recurso na página Provedores . O FeatureName valor da propriedade será exibido junto com os provedores predefinidos .NET Roles, .NET Users e .NET Profile.

Você pode usar a interface do usuário no Gerenciador do IIS para adicionar, editar, renomear ou remover provedores. Modificar um provedor resultará em uma alteração no arquivo Web.config (localizado na pasta .NET Framework versão 2.0).

Ao usar esse recurso de extensibilidade, você também deve escrever um <xref:System.Web.Management.Client.Module> objeto e um ModuleProvider objeto para registrar a ProviderFeature classe com o gerenciador de extensibilidade. O exemplo a seguir exibe a codificação dessas três classes junto com uma ProviderConfigurationSettings classe necessária para estabelecer a configuração do provedor.

Notas aos Implementadores

Ao herdar da ProviderFeature classe , você deve substituir os seguintes membros:

Construtores

ProviderFeature()

Inicializa uma nova instância da classe ProviderFeature.

Propriedades

ConnectionStringAttributeName

Obtém o nome da cadeia de conexão para o banco de dados do provedor.

ConnectionStringRequired

Obtém um valor que indica se uma cadeia de conexão é necessária para acessar o banco de dados.

FeatureName

Quando substituído em uma classe derivada, obtém o nome do recurso para o provedor.

ProviderBaseType

Quando substituído em uma classe derivada, obtém o tipo de provedor.

ProviderCollectionPropertyName

Quando substituído em uma classe derivada, obtém o nome da coleção de provedores.

ProviderConfigurationSettingNames

Quando substituído em uma classe derivada, obtém uma coleção com os nomes de configuração do provedor.

SectionName

Quando substituído em uma classe derivada, obtém a seção de configuração que configura o provedor.

SelectedProvider

Quando substituído em uma classe derivada, obtém o nome do provedor selecionado.

SelectedProviderPropertyName

Quando substituído em uma classe derivada, obtém o nome do atributo que especifica o provedor selecionado no momento.

Settings

Quando substituído em uma classe derivada, obtém as definições de configuração para o provedor.

Aplica-se a