Share via


ProfileModule Kelas

Definisi

Mengelola pembuatan profil pengguna dan peristiwa profil. Kelas ini tidak dapat diwariskan.

public ref class ProfileModule sealed : System::Web::IHttpModule
public sealed class ProfileModule : System.Web.IHttpModule
type ProfileModule = class
    interface IHttpModule
Public NotInheritable Class ProfileModule
Implements IHttpModule
Warisan
ProfileModule
Penerapan

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

Ketika profil pengguna diaktifkan, ASP.NET menggunakan ProfileModule untuk membuat profil pengguna dan menyimpannya di Profile properti dari saat ini HttpContext.

mengekspos ProfileModule peristiwa berikut yang dapat Anda tangani untuk mengonfigurasi autentikasi di aplikasi Anda:

  • Kejadian ini MigrateAnonymous , untuk memigrasikan pengaturan profil dari profil anonim ke profil terautentikasi saat pengguna anonim masuk.

  • Kejadian ini Personalize , untuk menyesuaikan cara profil pengguna dibuat.

  • Kejadian ini ProfileAutoSaving , untuk mengontrol bagaimana profil pengguna disimpan saat AutomaticSaveEnabled properti diatur ke true.

Untuk informasi tentang mengaktifkan profil pengguna, lihat Profil Elemen (ASP.NET Skema Pengaturan).

Konstruktor

ProfileModule()

Menginisialisasi instans baru kelas ProfileModule.

Metode

Dispose()

Merilis semua sumber daya yang ProfileModuledigunakan oleh .

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
Init(HttpApplication)

Memanggil kode inisialisasi saat ProfileModule objek dibuat.

MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Acara

MigrateAnonymous

Terjadi ketika pengguna anonim untuk profil masuk.

Personalize

Terjadi sebelum profil pengguna dibuat.

ProfileAutoSaving

Terjadi di akhir eksekusi halaman jika penyimpanan profil otomatis diaktifkan.

Berlaku untuk

Lihat juga