如何在DNN中正确设置自定义配置文件属性?

Joe*_*ack 2 dotnetnuke dotnetnuke-7

我正在尝试将自定义属性保存到DNN 7中的现有用户配置文件,但配置文件属性未设置.我必须正确理解一些事情.

那么,如何在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");
Run Code Online (Sandbox Code Playgroud)

注意:我也尝试过InitialiseProfile,但这并未改变行为.

Chr*_*ond 6

这是我如何从我为客户端的模块基类中的属性访问属性值.

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;
    }
}
Run Code Online (Sandbox Code Playgroud)