ProfileModule.MigrateAnonymous イベント

定義

あるプロファイルに対する匿名ユーザーがログインするときに発生します。

public:
 event System::Web::Profile::ProfileMigrateEventHandler ^ MigrateAnonymous;
public event System.Web.Profile.ProfileMigrateEventHandler MigrateAnonymous;
member this.MigrateAnonymous : System.Web.Profile.ProfileMigrateEventHandler 
Public Custom Event MigrateAnonymous As ProfileMigrateEventHandler 

イベントの種類

次の例は、匿名ユーザーをサポートする匿名 ID とプロファイル プロパティを有効にする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

注釈

このトピックのProfileModule例に示すように、グローバル イベントを使用Profile_MigrateAnonymousして、ASP.NET アプリケーションの Global.asax ファイル内の クラスのイベントにアクセスMigrateAnonymousできます。

イベントを MigrateAnonymous 使用すると、アプリケーションを匿名で使用しているユーザーがログインしたときに、プロファイル プロパティの値を匿名プロファイルから認証済みプロファイルにコピーできます。

ユーザー プロファイルが有効になっているアプリケーションを起動すると、ASP.NET は、 クラスから継承する 型 ProfileCommonの新しいクラスを ProfileBase 作成します。 厳密に型指定されたアクセサーは、プロファイル>構成セクションで定義されている各プロパティの クラスに<追加されますProfileCommonGetProfileメソッドを使用すると、ユーザー名にProfileCommon基づいてオブジェクトを取得できます。 現在の認証済みプロファイルの メソッドを使用 GetProfile して、匿名プロファイルのプロパティ値を取得できます。 匿名プロパティの値は、認証されたユーザーの現在のプロファイルにコピーできます。

適用対象

こちらもご覧ください