ProfileModule.MigrateAnonymous Ereignis

Definition

Tritt auf, wenn sich der anonyme Benutzer für ein Profil anmeldet.

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 

Ereignistyp

Beispiele

Das folgende Beispiel zeigt eine Web.config-Datei, die anonyme Identifikations- und Profileigenschaften ermöglicht, die anonyme Benutzer unterstützen.

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

Das folgende Codebeispiel zeigt das Ereignis, das MigrateAnonymous in der Datei Global.asax für eine ASP.NET-Anwendung enthalten ist. Das MigrateAnonymous Ereignis kopiert Profileigenschaftenwerte aus dem anonymen Profil in das Profil für den aktuellen Benutzer.

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

Hinweise

Sie können auf das MigrateAnonymous Ereignis der ProfileModule -Klasse in der Datei Global.asax für Ihre ASP.NET-Anwendung zugreifen, indem Sie das Profile_MigrateAnonymous globale Ereignis verwenden, wie im Beispiel für dieses Thema gezeigt.

Sie können das MigrateAnonymous -Ereignis verwenden, um Profileigenschaftswerte aus einem anonymen Profil in ein authentifiziertes Profil zu kopieren, wenn sich ein Benutzer anmeldet, der Ihre Anwendung anonym verwendet hat.

Wenn eine Anwendung gestartet wird, für die das Benutzerprofil aktiviert ist, erstellt ASP.NET eine neue Klasse vom Typ ProfileCommon, die von der ProfileBase -Klasse erbt. Stark typisierte Accessoren werden der ProfileCommon -Klasse für jede eigenschaft hinzugefügt, die im Abschnitt profilkonfiguration <> definiert ist. Mit einer GetProfile -Methode können Sie ein ProfileCommon Objekt basierend auf einem Benutzernamen abrufen. Sie können die GetProfile -Methode des aktuellen authentifizierten Profils verwenden, um die Eigenschaftswerte des anonymen Profils abzurufen. Die anonymen Eigenschaftswerte können dann in das aktuelle Profil für den authentifizierten Benutzer kopiert werden.

Gilt für:

Weitere Informationen