共用方式為


SqlProfileProvider 類別

定義

管理 SQL Server 資料庫中 ASP.NET 應用程式的設定檔資訊儲存。

public ref class SqlProfileProvider : System::Web::Profile::ProfileProvider
public class SqlProfileProvider : System.Web.Profile.ProfileProvider
type SqlProfileProvider = class
    inherit ProfileProvider
Public Class SqlProfileProvider
Inherits ProfileProvider
繼承

範例

以下程式碼範例展示了一個 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>

備註

ASP.NET 設定檔用於儲存及檢索使用者設定,儲存在資料庫等資料來源中。 使用者設定檔是利用 Profile 目前 HttpContext的屬性存取的。 房況資訊與房產價值由房況提供者管理。

ASP.NET 會用這個 SqlProfileProvider 類別來儲存和檢索使用 SQL Server 資料庫的 ASP.NET 應用程式設定檔設定。 要使用 , SqlProfileProvider您必須先建立 所使用的 SqlProfileProviderSQL Server 資料庫。 要建立 所使用的 SqlProfileProvider資料庫,請執行 aspnet_regsql.exe 工具,該工具位於 [drive:]\WINDOWS\Microsoft.NET\Framework\2.0versionNumber 資料夾中,並指定 -A p 選項 。 以下指令示範如何使用 aspnet_regsql.exe 執行檔:

aspnet_regsql.exe -A p

上述範例未指定所建立資料庫的名稱,因此會使用預設名稱。 預設資料庫名稱為 Aspnetdb。

機器設定包含一個名為 AspNetSqlProvider 的預設 SqlProfileProvider 實例,連接本地機器上的 SQL Server。 你可以使用這個提供者實例,或在 ASP.NET 應用程式的 Web.config 檔案中指定自己的。

備註

若設定檔提供者設定了使用整合安全性的連線字串,ASP.NET 應用程式的程序帳號必須擁有連接 SQL Server 資料庫的權限。

建構函式

名稱 Description
SqlProfileProvider()

建立 SqlProfileProvider 類別的執行個體。

屬性

名稱 Description
ApplicationName

取得或設定應用程式名稱,以儲存及檢索個人資料。

Description

獲得簡短且友善的說明,適合在管理工具或其他使用者介面(UI)中顯示。

(繼承來源 ProviderBase)
Name

設定時會用友善名稱來指代供應商。

(繼承來源 ProviderBase)

方法

名稱 Description
DeleteInactiveProfiles(ProfileAuthenticationOption, DateTime)

刪除那些最後活動日期在指定日期和時間之前的用戶設定檔資料。

DeleteProfiles(ProfileInfoCollection)

刪除資料來源中提供的設定檔屬性與資訊。

DeleteProfiles(String[])

刪除提供使用者名稱清單的資料來源中的個人資料屬性與資訊。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime, Int32, Int32, Int32)

取得最後活動日期發生於指定日期與時間,且使用者名稱與指定名稱相符的個人檔案資訊。

FindProfilesByUserName(ProfileAuthenticationOption, String, Int32, Int32, Int32)

取得使用者名稱與指定名稱相符的設定檔資訊。

GetAllInactiveProfiles(ProfileAuthenticationOption, DateTime, Int32, Int32, Int32)

取得最後活動日期發生於指定日期與時間之前的用戶設定檔資料。

GetAllProfiles(ProfileAuthenticationOption, Int32, Int32, Int32)

取得資料來源中使用者設定檔的資料。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetNumberOfInactiveProfiles(ProfileAuthenticationOption, DateTime)

取得資料來源中,最後活動日期發生於指定 userInactiveSinceDate日期或之前的設定檔數。

GetPropertyValues(SettingsContext, SettingsPropertyCollection)

從 SQL Server 設定檔資料庫取得設定檔屬性資訊與值。

GetType()

取得目前實例的 Type

(繼承來源 Object)
Initialize(String, NameValueCollection)

初始化 SQL Server 設定檔提供者,並依照 ASP.NET 應用程式設定檔中指定的屬性值。 此方法並非直接從你的程式碼中使用。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
SetPropertyValues(SettingsContext, SettingsPropertyValueCollection)

更新 SQL Server 設定檔資料庫,並加入指定的屬性值。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

另請參閱