Share via


ProfileMigrateEventArgs.AnonymousID プロパティ

定義

プロファイル プロパティ値の移行元の匿名プロファイルの匿名識別子を取得します。

public:
 property System::String ^ AnonymousID { System::String ^ get(); };
public string AnonymousID { get; }
member this.AnonymousID : string
Public ReadOnly Property AnonymousID As String

プロパティ値

プロファイル プロパティ値の移行元の匿名プロファイルの匿名識別子。

次のコード例は、匿名認証を有効にするWeb.config ファイルと、 MigrateAnonymous ASP.NET アプリケーションの Global.asax ファイルに含まれるイベントを示しています

次のコード例は、匿名ユーザーをサポートする匿名 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

注釈

プロパティには AnonymousID 、匿名ユーザーの一意識別子が含まれています。 アプリケーションを使用しているユーザーが匿名でログインすると、イベントを MigrateAnonymous 処理して、ユーザーの匿名プロファイルから認証されたプロファイルにプロファイル プロパティの値をコピーできます。

ユーザー プロファイルが有効になっているアプリケーションを起動すると、ASP.NET は、 クラスからProfileBase継承し、Web.config ファイルで指定されたプロファイル プロパティを含む 型ProfileCommonの新しいクラスを作成します。 クラスが ProfileCommon 生成されると、ユーザー名に GetProfile 基づいてオブジェクトを ProfileCommon 取得できるメソッドが追加されます。 現在のプロファイルの GetProfile メソッドを使用して、匿名プロファイルのプロパティ値を取得できます。 その後、匿名プロパティの値を、認証されたユーザーの現在のプロファイルにコピーできます。 匿名プロパティ値のコピーの例については、2 番目のコード例を参照してください。

適用対象

こちらもご覧ください