本文介绍了迁移匿名档案的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有迁移的所有参数的另一种方法隐含的?或任何其他好处。
Is there an alternate way that migrates all parameters implicit? Or any other advantages.
:
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 ?
推荐答案
这是要走的路。但我建议推广。相反,硬编码每个属性你可以通过ProfileBase.Properties采集。沿着这些路线的内容:
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);
}
由于属性组重新psented作为属性名称的一部分$ P $(如Settings.Theme重presents设置组内的主题属性)上述code也应与属性组工作
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.
这篇关于迁移匿名档案的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!