共用方式為


設定檔提供者的 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 應用程式也可以使用相同的設定檔資訊,方法是指定相同的應用程式名稱。

如果未指定這個屬性 (Attribute),.NET Framework 包含的設定檔提供者便會使用 ApplicationName 屬性 (Property) 的 ApplicationVirtualPath 值。

commandTimeout

選擇性 Int32 屬性。

指定發送至成員資格資料來源的命令逾時前經過的秒數。 SQL 提供者在建立 SqlCommand 物件時會使用這項逾時。 根據預設,ASP.NET 組態中不會設定這項屬性 (Attribute)。 因此,會使用 30 秒鐘的 ADO.NET 預設值。 如果設定這個屬性,對於所有發出至資料庫的 SQL 命令,SQL 提供者會使用設定的逾時值。

預設為 30 (ADO.NET 預設)。

description

選擇性 String 屬性。

指定設定檔提供者執行個體的說明。

子項目

無。

父項目

項目

描述

providers

為使用者設定檔定義設定檔提供者的集合。

profile

設定應用程式的使用者設定檔。

configuration

指定 Common Language Runtime 和 .NET Framework 應用程式所使用之每個組態檔中的根項目 (Root Element)。

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 Information Services (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> 項目

設定檔提供者的 remove 項目 (ASP.NET 設定結構描述)

設定檔提供者的 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