2009-11-02 55 views
8

是否有一种可以迁移所有隐式参数的替代方法?或者其他任何优势。迁移匿名配置文件的最佳方法

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

} 

或者这是最好的/唯一途径?

回答

8

这是要走的路。但我会建议一个泛化。而不是硬编码每个属性,你可以循环访问ProfileBase.Properties集合。沿着这些线的东西:

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

由于属性组被表示为属性名称的一部分(例如,“Settings.Theme”表示设置组内的主题属性)上面的代码还应与属性组工作。

+0

这也会涉及一组属性? – 2009-12-14 12:26:23