Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to Migrate Anonymous Profile

Is there an alternate way that migrates all parameters implicit? Or any other advantages.

From MSDN:

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

}

Or is this the best/only way ?

like image 229
Thomas Sandberg Avatar asked Nov 02 '09 12:11

Thomas Sandberg


1 Answers

This is the way to go. But I would suggest a generalization. Instead of hardcoding each property you could loop through the ProfileBase.Properties collection. Something along these lines:

var anonymousProfile = Profile.GetProfile(args.AnonymousID);
foreach(var property in anonymousProfile.PropertyValues)
{
    Profile.SetPropertyValue(property.Name, property.PropertyValue);
}

Since property groups are represented as part of the property names (e.g. "Settings.Theme" represents the Theme property within the Settings group) the above code should also work with property groups.

like image 164
Peter Lillevold Avatar answered Nov 05 '22 07:11

Peter Lillevold