共用方式為


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 Global.asax 檔案中包含的事件,用於一個 ASP.NET 應用程式。 事件會 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 事件,用來控制當 AutomaticSaveEnabled 屬性設定為 true時,使用者設定檔如何被儲存。

關於啟用使用者設定檔的資訊,請參閱設定檔元素(ASP.NET 設定結構)。

建構函式

名稱 Description
ProfileModule()

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

方法

名稱 Description
Dispose()

釋放所有由 ProfileModule.

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
Init(HttpApplication)

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

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

事件

名稱 Description
MigrateAnonymous

當匿名用戶登入個人檔案時會發生。

Personalize

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

ProfileAutoSaving

若啟用自動設定檔儲存,則會在頁面執行結束時發生。

適用於

另請參閱