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

发布于 2024-08-09 05:03:45 字数 884 浏览 6 评论 0原文

是否有另一种方法可以隐式迁移所有参数?或者有什么其他优点。

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

}

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

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩物 2024-08-16 05:03:45

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

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

由于属性组表示为属性名称的一部分(例如“Settings.Theme”表示“设置”组中的“主题”属性),因此上述代码也应该适用于属性组。

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.

幸福还没到 2024-08-16 05:03:45

我正确理解你的问题吗?

登录期间迁移配置文件属性

http://msdn.microsoft.com/en-我们/library/taab950e.aspx

Did I understand your question correctly?

Migrating Profile Properties During Log On

http://msdn.microsoft.com/en-us/library/taab950e.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文