ProfileModule Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hanterar skapandet av användarprofilen och profilhändelserna. Det går inte att ärva den här klassen.
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
- Arv
-
ProfileModule
- Implementeringar
Exempel
I följande exempel visas en Web.config fil som möjliggör anonym identifiering och profilegenskaper som stöder anonyma användare.
<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>
I följande kodexempel visas händelsen MigrateAnonymous som ingår i filen Global.asax för ett ASP.NET program. Händelsen MigrateAnonymous kopierar profilegenskapsvärden från den anonyma profilen till profilen för den aktuella användaren.
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
Kommentarer
När användarprofilen är aktiverad använder ASP.NET ProfileModule för att skapa användarprofilen och lagra den i egenskapen Profile för den aktuella HttpContext.
Exponerar ProfileModule följande händelser som du kan hantera för att konfigurera autentisering i ditt program:
Händelsen för att migrera profilinställningar från en anonym profil till en autentiserad MigrateAnonymous profil när en anonym användare loggar in.
Händelsen Personalize för att anpassa hur användarprofilen skapas.
Händelsen ProfileAutoSaving för att styra hur användarprofilen sparas när AutomaticSaveEnabled egenskapen är inställd på
true.
Information om hur du aktiverar användarprofilen finns i profile Element (ASP.NET Settings Schema).
Konstruktorer
| Name | Description |
|---|---|
| ProfileModule() |
Initierar en ny instans av ProfileModule klassen. |
Metoder
| Name | Description |
|---|---|
| Dispose() |
Släpper alla resurser som används av ProfileModule. |
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| Init(HttpApplication) |
Anropar initieringskod när ett ProfileModule objekt skapas. |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Händelser
| Name | Description |
|---|---|
| MigrateAnonymous |
Inträffar när den anonyma användaren för en profil loggar in. |
| Personalize |
Inträffar innan användarprofilen skapas. |
| ProfileAutoSaving |
Inträffar i slutet av sidkörningen om automatisk profilbesparing är aktiverad. |