ProfileMigrateEventArgs.AnonymousID Egenskap

Definition

Hämtar den anonyma identifieraren för den anonyma profil som profilens egenskapsvärden ska migreras från.

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

Egenskapsvärde

Den anonyma identifieraren för den anonyma profil som profilens egenskapsvärden ska migreras från.

Exempel

Följande kodexempel visar en Web.config fil som möjliggör anonym autentisering och händelsen MigrateAnonymous som ingår i filen Global.asax för ett ASP.NET program

I följande kodexempel 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

Egenskapen AnonymousID innehåller den unika identifieraren för en anonym användare. När någon som har använt ditt program anonymt loggar in kan du hantera MigrateAnonymous händelsen för att kopiera profilegenskapsvärden från användarens anonyma profil till deras autentiserade profil.

När ett program som har användarprofilen aktiverad startas skapar ASP.NET en ny klass av typen ProfileCommon, som ärver från klassen ProfileBase och innehåller profilegenskaper som anges i filen Web.config. ProfileCommon När klassen genereras läggs en GetProfile metod till som gör att du kan hämta ett ProfileCommon objekt baserat på ett användarnamn. Du kan använda metoden för GetProfile den aktuella profilen för att hämta egenskapsvärdena för den anonyma profilen. De anonyma egenskapsvärdena kan sedan kopieras till den aktuella profilen för den autentiserade användaren. Se det andra kodexemplet för ett exempel på kopiering av anonyma egenskapsvärden.

Gäller för

Se även