Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Kentico CMS中获取UserCustomData_C#_Kentico - Fatal编程技术网

C# 如何在Kentico CMS中获取UserCustomData

C# 如何在Kentico CMS中获取UserCustomData,c#,kentico,C#,Kentico,我想为Kentico CMS中当前经过身份验证的用户获取一些自定义数据。我尝试了以下方法但没有成功: CMSContext.CurrentUser.UserCustomData["CustomFieldName"]; CMSContext.CurrentUser.UserCustomData.GetValue("CustomFieldName"); 看起来UserCustomData属性应该是这个信息的数据容器,但当我试图访问它时,我总是得到空引用。如何在不为CMS_用户表创建新查询或对象包装

我想为Kentico CMS中当前经过身份验证的用户获取一些自定义数据。我尝试了以下方法但没有成功:

CMSContext.CurrentUser.UserCustomData["CustomFieldName"];
CMSContext.CurrentUser.UserCustomData.GetValue("CustomFieldName");

看起来UserCustomData属性应该是这个信息的数据容器,但当我试图访问它时,我总是得到空引用。如何在不为CMS_用户表创建新查询或对象包装的情况下访问此数据?

以下内容将允许您访问CMS_用户表中的任何字段:

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

以防有人好奇。“UserCustomData”字段是数据库中的一个xml字段,可以通过Kentico API进行访问,就像它是键值容器一样。您可以暂时将信息存储在其中,但我建议您不要这样做,因为您可能最终需要对稍后输入的数据做一些处理,并希望将其作为一个新字段。“CustomData”字段也可用于任何其他信息对象,但我建议不要使用它们。因此“UserCustomData”不是CMS_用户表上自定义数据字段的包装器?不-所有Kentico数据对象都类似于.Net数据集对象的包装器。在文档/页面类型、自定义表或系统表的“字段”选项卡中添加新字段时,它会在SQL数据库中添加一个新列,然后显示在该数据集中。GetValue方法和方括号运算符只是根据SQL列的名称检索列值。如果您想进行实验,可以尝试在UserCustomData字段中存储一些内容,然后使用“ui.GetValue(“UserCustomData”)”—您将以字符串形式返回xml。啊,我知道UserCustomData字段现在在哪里了。它在CMS_用户设置中,而不是CMS_用户。我知道映射是如何工作的,我只是不知道这个字段是从哪里来的。现在,我正在查看UserInfo类的元数据,其中有很多内容,而不仅仅是CMS_User中的内容。