在使用.NET API SenseNet.Client定义sensenet上的组成员时,我遇到了问题。
我需要创建一个自动过程来在sensenet上添加用户和组。我知道如何创建用户和组,但是我没有找到任何关于将用户添加到组中的信息。
下面是我用来创建组的代码:
var group = Content.CreateNew("/Root/IMS/BuiltIn/OUtest", "Group", "testGroup");
group["Name"] = "testGroup";
group["DisplayName"] = "testGroup";
await group.SaveAsync();发布于 2017-01-04 20:12:11
为了支持这个场景,客户端API中有一个组类,它包含几个修改组成员身份的方法。它是从主要的内容类继承而来的,所以它有其所有的特性。
如果您已经有一个组id,您可以选择静态API来修改成员资格(下面的idArray应该只包含新成员,您必须知道现有成员,这只是‘增量’)。
// add new members to a group
await Group.AddMembersAsync(group.Id, idArray);...or实例API,如果您要创建一个新的组(请注意泛型创建者方法):
// create group using the generic method
var group = Content.CreateNew<Group>("/Root/IMS/BuiltIn/OUtest", "Group", "testGroup");
group["Name"] = "testGroup";
group["DisplayName"] = "testGroup";
await group.SaveAsync();
// add new members
await group.AddMembersAsync(idArray);
// remove members
await group.RemoveMembersAsync(deletedUsersArray);上面的方法会立即进行其余的调用,因此不需要在它们之后调用Save。
https://stackoverflow.com/questions/41471239
复制相似问题