ProfileMigrateEventArgs.AnonymousID Eigenschaft

Definition

Ruft den anonymen Bezeichner für das anonyme Profil ab, aus dem Profileigenschaftswerte migriert werden sollen.

public:
 property System::String ^ AnonymousID { System::String ^ get(); };
public string AnonymousID { get; }
member this.AnonymousID : string
Public ReadOnly Property AnonymousID As String

Eigenschaftswert

Der anonyme Bezeichner für das anonyme Profil, aus dem Profileigenschaftswerte migriert werden sollen.

Beispiele

Die folgenden Codebeispiele zeigen eine Web.config-Datei, die die anonyme Authentifizierung ermöglicht, und das Ereignis, das MigrateAnonymous in der Datei Global.asax für eine ASP.NET Anwendung enthalten ist

Das folgende Codebeispiel 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

Die AnonymousID -Eigenschaft enthält den eindeutigen Bezeichner für einen anonymen Benutzer. Wenn sich jemand, der Ihre Anwendung verwendet hat, anonym anmeldet, können Sie das MigrateAnonymous Ereignis behandeln, um Profileigenschaftenwerte aus dem anonymen Profil des Benutzers in das authentifizierte Profil zu kopieren.

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 und Profileigenschaften enthält, die in der Web.config-Datei angegeben sind. Wenn die ProfileCommon -Klasse generiert wird, wird eine GetProfile -Methode hinzugefügt, mit der Sie ein ProfileCommon Objekt basierend auf einem Benutzernamen abrufen können. Sie können die GetProfile -Methode des aktuellen 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. Im zweiten Codebeispiel finden Sie ein Beispiel für das Kopieren anonymer Eigenschaftswerte.

Gilt für:

Weitere Informationen