如何在DNN中正确设置自定义配置文件属性? [英] How do you properly set a custom profile property in DNN?

查看:92
本文介绍了如何在DNN中正确设置自定义配置文件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义属性保存到DNN 7中的现有用户配置文件,但是未设置配置文件属性.我一定是在理解错误.

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.

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

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");

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

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

推荐答案

这是我从客户端的模块基类中的属性访问propertyvalue的方式.

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;
    }
}

这篇关于如何在DNN中正确设置自定义配置文件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆