2009-11-02 12 views
8

Czy istnieje alternatywny sposób migracji wszystkich parametrów niejawnie? Lub inne korzyści.Najlepszy sposób na migrację anonimowego profilu

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

} 

Albo jest to najlepszy/jedyny sposób?

Odpowiedz

8

To jest droga. Ale sugerowałbym uogólnienie. Zamiast kodowania każdej właściwości można przechodzić przez kolekcję ProfileBase.Properties. Coś w taki sposób:

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

Ponieważ grupy właściwości są reprezentowane jako część nazwy właściwości (na przykład „Settings.Theme” oznacza właściwość motyw w grupie Ustawienia) powyżej kod powinien również pracować z grupami własności.

+0

Czy to też zajmie grupy nieruchomości? –

Powiązane problemy