如何在 Kentico CMS 中获取 UserCustomData
How to get UserCustomData in Kentico CMS
我想为 Kentico CMS 中当前经过身份验证的用户获取一些自定义数据。我尝试了以下但没有成功:
CMSContext.CurrentUser.UserCustomData["CustomFieldName"];
CMSContext.CurrentUser.UserCustomData.GetValue("CustomFieldName");
看起来 UserCustomData 属性 应该是此信息的数据容器,但当我尝试访问它时,我总是收到空引用。如何在不为 CMS_User table 创建新查询或对象包装器的情况下访问此数据?
以下将允许您访问 CMS_User table 中的任何字段:
// instantiate a UserInfo object and populate it with data
// by passing in the user's UserID. Here I've passed in
// the current user's UserID
UserInfo ui = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserID);
// retrieve data from the db by passing in the field name
var aVariable = ui.GetValue("FieldName");
我想为 Kentico CMS 中当前经过身份验证的用户获取一些自定义数据。我尝试了以下但没有成功:
CMSContext.CurrentUser.UserCustomData["CustomFieldName"];
CMSContext.CurrentUser.UserCustomData.GetValue("CustomFieldName");
看起来 UserCustomData 属性 应该是此信息的数据容器,但当我尝试访问它时,我总是收到空引用。如何在不为 CMS_User table 创建新查询或对象包装器的情况下访问此数据?
以下将允许您访问 CMS_User table 中的任何字段:
// instantiate a UserInfo object and populate it with data
// by passing in the user's UserID. Here I've passed in
// the current user's UserID
UserInfo ui = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserID);
// retrieve data from the db by passing in the field name
var aVariable = ui.GetValue("FieldName");