迁移匿名配置文件的最佳方式

Tho*_*erg 8 asp.net profiling anonymous migrate

是否存在隐式迁移所有参数的替代方法?或任何其他优点.

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

}
Run Code Online (Sandbox Code Playgroud)

或者这是最好/唯一的方式?

Pet*_*old 8

这是要走的路.但我建议进行概括.您可以循环遍历ProfileBase.Properties集合,而不是对每个属性进行硬编码.这些方面的东西:

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

由于属性组表示为属性名称的一部分(例如"Settings.Theme"表示Settings组中的Theme属性),因此上述代码也应该与属性组一起使用.