Bagikan melalui


ProfileMigrateEventHandler Delegasikan

Definisi

Mewakili metode yang akan menangani MigrateAnonymous peristiwa ProfileModule kelas.

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)

Parameter

sender
Object

Yang ProfileModule mengangkat MigrateAnonymous peristiwa.

e
ProfileMigrateEventArgs

ProfileMigrateEventArgs yang berisi data peristiwa.

Contoh

Contoh kode berikut menunjukkan file Web.config yang memungkinkan autentikasi anonim dan peristiwa yang MigrateAnonymous disertakan dalam file Global.asax untuk aplikasi ASP.NET.

Contoh kode berikut menunjukkan file Web.config yang memungkinkan identifikasi anonim dan properti profil yang mendukung pengguna anonim.

<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>  

Contoh kode berikut menunjukkan peristiwa yang MigrateAnonymous disertakan dalam file Global.asax untuk aplikasi ASP.NET. Peristiwa MigrateAnonymous menyalin nilai properti profil dari profil anonim ke profil untuk pengguna saat ini.

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

Keterangan

ProfileMigrateEventHandler Delegasi didefinisikan untuk MigrateAnonymous peristiwa ProfileModule kelas. Anda dapat mengakses MigrateAnonymous peristiwa ProfileModule kelas di file Global.asax untuk aplikasi ASP.NET Anda seperti yang ditunjukkan dalam contoh untuk topik ini.

Anda dapat menggunakan peristiwa tersebut MigrateAnonymous untuk menyalin nilai properti profil dari profil anonim ke profil terautentikasi saat seseorang yang secara anonim menggunakan aplikasi Anda masuk.

Ketika aplikasi yang mengaktifkan profil pengguna dimulai, ASP.NET membuat kelas jenis ProfileCommonbaru , yang mewarisi dari ProfileBase kelas . ProfileCommon Saat kelas dibuat, berdasarkan properti profil yang ditentukan dalam file Web.config, GetProfile metode ditambahkan yang memungkinkan Anda mengambil ProfileCommon objek berdasarkan nama pengguna. Anda dapat menggunakan GetProfile metode profil saat ini untuk mengambil nilai properti profil anonim. Nilai properti anonim kemudian dapat disalin ke profil saat ini untuk pengguna yang diautentikasi.

Metode Ekstensi

GetMethodInfo(Delegate)

Mendapatkan objek yang mewakili metode yang diwakili oleh delegasi yang ditentukan.

Berlaku untuk

Lihat juga