Share via


profile 的 providers 的 add 元素(ASP.NET 设置架构)

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

向用户配置文件提供程序集合添加配置文件提供程序实例。

此元素是 .NET Framework 2.0 版中的新元素。

<add 
    name="provider name" 
    type="fully qualified type reference"
    connectionStringName="connection string identifier"
    commandTimeout="number of seconds before a command times out"
    description="description of the provider instance"
    applicationName="application name for stored profile information" />

特性和元素

以下几节描述了特性、子元素和父元素。

特性

特性

说明

name

必选的 String 特性。

指定提供程序实例的名称。 这是用于 <profile> 元素的 defaultProvider 特性的值,该值将提供程序实例标识为默认的配置文件提供程序。 该提供程序的 name 还用于在 Providers 集合中对该提供程序进行索引。

type

必选的 String 特性。

指定实现 ProfileProvider 抽象基类的类型。

connectionStringName

必选的 String 特性。

指定在 <connectionStrings> 元素中定义的连接字符串的名称。 指定的连接字符串将由正在添加的提供程序使用。

applicationName

可选的 String 特性。

指定数据源中存储配置文件数据的应用程序的名称。 该应用程序名称使得多个 ASP.NET 应用程序能够使用同一个数据库,而不会遇到不同应用程序存在重复配置文件数据的情况。 或者,通过指定相同的应用程序名称,多个 ASP.NET 应用程序可以使用相同的配置文件信息。

如果未指定此特性,则 .NET Framework 附带的配置文件提供程序使用 ApplicationName 属性的 ApplicationVirtualPath 值。

commandTimeout

可选的 Int32 特性。

指定在向成员资格数据源发出的命令超时之前等待的时间(以秒为单位)。 SQL 提供程序在创建 SqlCommand 对象时,使用该超时属性。 默认情况下 ASP.NET 配置中并未设置该特性。 因此,使用 ADO.NET 默认值 30 秒。 如果设置了该特性,则 SQL 提供程序对向数据库发出的所有 SQL 命令使用配置的超时值。

默认值为 30(ADO.NET 默认值)。

description

可选的 String 特性。

指定配置文件提供程序实例的说明。

子元素

无。

父元素

元素

说明

providers

为用户配置文件定义一个配置文件提供程序的集合。

profile

为应用程序配置用户配置文件。

configuration

指定公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。

system.web

为 ASP.NET 配置节指定根元素。

备注

可以在 add 元素中包括所实现的自定义配置文件提供程序的其他特性。 有关示例,请参见Sample Profile Provider Implementation

有关访问和修改应用程序代码中 profile 元素的配置值的信息,请参见 ProfileSection

默认配置

下面的默认 profile 元素在 .NET Framework 2.0 版的 Machine.config 文件中配置。

  <providers>
    <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
  </providers> 

示例

下面的代码示例演示如何创建 ASP.NET 应用程序的 Web.config 文件,该应用程序配置为使用 SqlProfileProvider 提供程序。

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial 
         Catalog=aspnetdb;" />
  </connectionStrings>

  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />
    </authentication>

    <authorization>
      <deny users="?" />
    </authorization>

    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
      <providers>
        <clear/>
        <add name="SqlProvider" 
             type="System.Web.Security.SqlMembershipProvider" 
             connectionStringName="SqlServices"
             applicationName="SampleApplication"
             enablePasswordRetrieval="true"
             enablePasswordReset="true"
             passwordFormat="Encrypted"
             requiresQuestionAndAnswer="true" />
      </providers>
    </membership>

    <profile defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="SqlServices"
             applicationName="SampleApplication"
             description="SqlProfileProvider for SampleApplication" />
      </providers>

      <properties>
        <add name="ZipCode" />
        <add name="CityAndState" />
      </properties>
    </profile>
  </system.web>
</configuration>

元素信息

配置节处理程序

System.Web.Configuration.ProfileSection

配置成员

ProfileSection.Providers

可配置的位置

Machine.config

根级别的 Web.config

应用程序级别的 Web.config

要求

Microsoft Internet 信息服务 (IIS) 版本 5.0、5.1 或 6.0

.NET Framework 2.0 版

Microsoft Visual Studio 2005

请参见

任务

How to: Lock ASP.NET Configuration Settings

参考

profile 元素(ASP.NET 设置架构)

system.web 元素(ASP.NET 设置架构)

<configuration> 元素

profile 的 providers 的 remove 元素(ASP.NET 设置架构)

profile 的 providers 的 clear 元素(ASP.NET 设置架构)

ProfileSection

System.Configuration

System.Web.Configuration

概念

ASP.NET Profile Properties Overview

ASP.NET Configuration Overview

ASP.NET Server Controls and Browser Capabilities

Securing ASP.NET Configuration

ASP.NET Configuration Scenarios

其他资源

ASP.NET Configuration Files

ASP.NET 配置设置

常规配置设置 (ASP.NET)

ASP.NET Configuration API