ProfileModule 類別

定義

管理使用者設定檔的建立和設定檔事件。 此類別無法獲得繼承。

public ref class ProfileModule sealed : System::Web::IHttpModule
public sealed class ProfileModule : System.Web.IHttpModule
type ProfileModule = class
    interface IHttpModule
Public NotInheritable Class ProfileModule
Implements IHttpModule
繼承
ProfileModule
實作

範例

下列範例顯示Web.config檔案,可啟用支援匿名使用者的匿名識別和配置檔案屬性。

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

    <anonymousIdentification enabled="true" />  

    <profile enabled="true" defaultProvider="AspNetSqlProvider">  
      <properties>  
        <add name="ZipCode" allowAnonymous="true" />  
        <add name="CityAndState" allowAnonymous="true" />  
        <add name="StockSymbols" type="System.Collections.ArrayList" allowAnonymous="true" />  
      </properties>  
    </profile>  
  </system.web>  
</configuration>  

下列程式碼範例顯示 MigrateAnonymous ASP.NET 應用程式之 Global.asax 檔案中包含的事件。 事件會將 MigrateAnonymous 配置檔案屬性值從匿名配置檔案複製到目前使用者的設定檔。

public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
  ProfileCommon anonymousProfile = Profile.GetProfile(args.AnonymousID);

  Profile.ZipCode = anonymousProfile.ZipCode;
  Profile.CityAndState = anonymousProfile.CityAndState;
  Profile.StockSymbols = anonymousProfile.StockSymbols;

  ////////
  // Delete the anonymous profile. If the anonymous ID is not 
  // needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID);
  AnonymousIdentificationModule.ClearAnonymousIdentifier(); 

  // Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, true);

}
Public Sub Profile_OnMigrateAnonymous(sender As Object, args As ProfileMigrateEventArgs)
  Dim anonymousProfile As ProfileCommon = Profile.GetProfile(args.AnonymousID)

  Profile.ZipCode = anonymousProfile.ZipCode
  Profile.CityAndState = anonymousProfile.CityAndState
  Profile.StockSymbols = anonymousProfile.StockSymbols

  ''''''''
  ' Delete the anonymous profile. If the anonymous ID is not 
  ' needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID)
  AnonymousIdentificationModule.ClearAnonymousIdentifier()

  ' Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, True)
End Sub

備註

啟用使用者設定檔時,ASP.NET 會使用 ProfileModule 來建立使用者設定檔,並將它儲存在 Profile 目前 HttpContext 的 屬性中。

ProfileModule 公開下列您可以處理的事件,以在應用程式中設定驗證:

  • 事件 MigrateAnonymous ,在匿名使用者登入時,將設定檔設定從匿名設定檔移轉至已驗證的設定檔。

  • 事件 Personalize ,用來自訂使用者設定檔的建立方式。

  • 事件 ProfileAutoSaving ,控制當 屬性設定為 trueAutomaticSaveEnabled ,使用者設定檔的儲存方式。

如需啟用使用者設定檔的資訊,請參閱 設定檔元素 (ASP.NET 設定架構)

建構函式

ProfileModule()

初始化 ProfileModule 類別的新執行個體。

方法

Dispose()

釋放 ProfileModule 所使用的所有資源。

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Init(HttpApplication)

ProfileModule 物件建立時,呼叫初始化程式碼。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

事件

MigrateAnonymous

當設定檔的匿名使用者登入時發生。

Personalize

在使用者設定檔建立之前發生。

ProfileAutoSaving

在頁面執行結束時發生 (如果自動設定檔儲存已啟用)。

適用於

另請參閱