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

时间:2014-08-26 18:08:52

标签: 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");

注意:我也尝试过InitialiseProfile,但这并没有改变行为。

1 个答案:

答案 0 :(得分: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;
    }
}
相关问题