How do you properly set a custom profile property in DNN?

霸气de小男生 提交于 2019-12-24 00:58:25

问题


I'm trying to save a custom property to an existing user profile in DNN 7, but the profile property is not getting set. I must be understanding something incorrectly.

So, how do you properly set a custom profile property in DNN?

UserInfo.Profile.SetProfileProperty("key","value")

// I expect this to return "value", but it's always ""
var value = UserInfo.Profile.GetProfileProperty("key");

// Even if I save it...
ProfileController.UpdateUserProfile(UserInfo);

// It always returns ""
var savedValue = UserInfo.Profile.GetProfileProperty("key");

Note: I also tried InitialiseProfile but that didn't change the behavior.


回答1:


Here is how I am accessing a propertyvalue from a property in a module base class I have for a client.

public string SomeKey
{
    get
    {
        var ppd = UserInfo.Profile.GetProperty("SomeKey");
        if (ppd.PropertyValue == string.Empty)
        {

            var SomeKeyValue = "blah"
            //update the user's profile property
            UserInfo.Profile.SetProfileProperty("SomeKey", SomeKeyValue);
            //save the user
            DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, UserInfo);
            //retrieve again
            return SomeKey;
        }
        string returnValue = ppd.PropertyValue ??
                             (String.IsNullOrEmpty(ppd.DefaultValue) ? String.Empty : ppd.DefaultValue);
        return returnValue;
    }
}


来源:https://stackoverflow.com/questions/25512411/how-do-you-properly-set-a-custom-profile-property-in-dnn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!