ProfileMigrateEventHandler 代理人

定義

代表將處理 MigrateAnonymous 類別事件 ProfileModule 的方法。

public delegate void ProfileMigrateEventHandler(System::Object ^ sender, ProfileMigrateEventArgs ^ e);
public delegate void ProfileMigrateEventHandler(object sender, ProfileMigrateEventArgs e);
type ProfileMigrateEventHandler = delegate of obj * ProfileMigrateEventArgs -> unit
Public Delegate Sub ProfileMigrateEventHandler(sender As Object, e As ProfileMigrateEventArgs)

參數

sender
Object

然後ProfileModule事件就這樣提升了。MigrateAnonymous

範例

以下程式碼範例展示了一個 Web.config 檔案,該檔案啟用匿名認證,以及 MigrateAnonymous Global.asax 檔案中包含的事件,適用於 ASP.NET 應用程式。

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

備註

ProfileMigrateEventHandler代表是為MigrateAnonymousProfileModule該類別事件所定義的。 你可以在 ASP.NET 應用程式的 Global.asax 檔案中存取 MigrateAnonymous 類別的 ProfileModule 事件,如本主題範例所示。

當匿名使用你應用程式的人登入時,你可以利用這個 MigrateAnonymous 事件將個人資料的屬性值從匿名檔案複製到已認證的檔案。

當啟用使用者設定檔的應用程式啟動時,ASP.NET 會建立一個新的類型 ProfileCommon類別,該類別繼承自該 ProfileBase 類別。 當 ProfileCommon 類別產生時,根據 Web.config 檔案中指定的設定檔屬性,會新增一個 GetProfile 方法,讓你能根據使用者名稱檢索 ProfileCommon 物件。 你可以利用 GetProfile 目前設定檔的方法來取得匿名設定檔的屬性值。 匿名屬性值可複製至已認證使用者的當前設定檔。

擴充方法

名稱 Description
GetMethodInfo(Delegate)

取得一個代表指定代理所代表方法的物件。

適用於

另請參閱