2009-11-02 2 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

이것은 또한 속성 그룹을 사용합니까? –

관련 문제