【问题标题】:How do you properly set a custom profile property in DNN?如何在 DNN 中正确设置自定义配置文件属性?
【发布时间】:2014-08-26 18:08:51
【问题描述】:

我正在尝试将自定义属性保存到 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,但这并没有改变行为。

【问题讨论】:

    标签: dotnetnuke dotnetnuke-7


    【解决方案1】:

    以下是我如何从我为客户拥有的模块基类中的属性访问属性值。

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

    【讨论】:

    • 谢谢!我认为我缺少的部分是我没有通过 UI 为用户设置属性/类型。
    • 啊,是的,我想我也忘了提到那部分:D
    猜你喜欢
    • 1970-01-01
    • 2017-03-16
    • 2011-03-18
    • 2012-09-09
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    相关资源
    最近更新 更多