How do you properly set a custom profile property

2019-07-17 04:15发布

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条回答
Melony?
2楼-- · 2019-07-17 04:34

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;
    }
}
查看更多
登录 后发表回答