ProfileModule.MigrateAnonymous Kejadian
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Terjadi ketika pengguna anonim untuk profil masuk.
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
Jenis Acara
Contoh
Contoh 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
Anda dapat mengakses peristiwa MigrateAnonymous dari kelas ProfileModule di file Global.asax untuk aplikasi ASP.NET Anda dengan menggunakan peristiwa global Profile_MigrateAnonymous, seperti yang ditunjukkan dalam contoh untuk topik ini.
Anda dapat menggunakan peristiwa untuk MigrateAnonymous menyalin nilai properti profil dari profil anonim ke profil terautentikasi saat pengguna yang telah secara anonim menggunakan aplikasi Anda masuk.
Ketika aplikasi yang mengaktifkan profil pengguna dimulai, ASP.NET membuat kelas jenis ProfileCommonbaru , yang mewarisi dari ProfileBase kelas . Aksesor yang sangat ditik ditambahkan ke ProfileCommon kelas untuk setiap properti yang ditentukan di bagian <konfigurasi profil> . Metode GetProfile memungkinkan Anda mengambil ProfileCommon objek berdasarkan nama pengguna. Anda dapat menggunakan GetProfile metode profil terautentikasi saat ini untuk mengambil nilai properti profil anonim. Nilai properti anonim kemudian dapat disalin ke profil saat ini untuk pengguna yang diautentikasi.