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

}

それともこれが最良/唯一の方法ですか?

4

2 に答える 2

8

これが進むべき道です。しかし、私は一般化を提案します。各プロパティをハードコーディングする代わりに、 ProfileBase.Propertiesコレクションをループできます。これらの行に沿ったもの:

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

プロパティ グループはプロパティ名の一部として表されるため (たとえば、「Settings.Theme」は Settings グループ内の Theme プロパティを表します)、上記のコードはプロパティ グループでも機能するはずです。

于 2009-12-14T09:28:41.093 に答える
0

あなたの質問を正しく理解しましたか?

ログオン中のプロファイル プロパティの移行

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

于 2009-12-13T01:24:59.013 に答える