【发布时间】:2015-04-09 22:11:12
【问题描述】:
我的系统有用户登录以注册/更新他们的帐户。在后端,我们已经设置了一个组并检查它们是否已经存在。如果用户正在续订(已经在 OU 中),我们还更改了系统并将用户移至新的 OU。
我现在要做的是在用户续订或注册时为其应用一个新组。导致用户成为 2 个组的成员。
DirectoryEntry instructorRoot = new DirectoryEntry(LDAP_OU_DIR); //root binding
instructorRoot.AuthenticationType = AuthenticationTypes.Signing | AuthenticationTypes.Secure | AuthenticationTypes.Sealing | AuthenticationTypes.FastBind;
DirectoryEntry instructor = new DirectoryEntry(LDAPRoot); //default value
instructor.AuthenticationType = instructorRoot.AuthenticationType;
/*Here is where im trying to look for the TestGroup group*/
DirectoryEntry instructorGroup = instructorRoot.Children.Find("CN="+TestGroup, "group");
instructorGroup.AuthenticationType = instructorRoot.AuthenticationType;
instructor = instructorRoot.Children.Add("CN=" + hfUser.Value, "user");
instructor.CommitChanges();
instructor.Properties["userPrincipalName"].Value = hfUser.Value + "@" + LDAPRoot;
instructor.Properties["sAMAccountName"].Value = hfUser.Value; //login name
instructor.CommitChanges();
/*Here is where im trying to add the InstTest group to the user*/
instructorGroup.Properties["member"].Add(instructor.Properties["distinguishedName"].Value); //add to instructors group
instructorGroup.CommitChanges(); //commit changes so that we can set primary group next
instructorGroup.Close();//close
instructor.Properties["PrimaryGroupID"].Value = 109929; //set primarygroup to instructors
instructor.CommitChanges();
【问题讨论】:
-
另外我想补充一点,每个用户都是一个组的“成员”,并且该组被设置为主要组。当每个用户通过网页注册时,我想让这些帐户成为我的测试组 AInstTest(以编程方式)的“成员”。
标签: c# active-directory active-directory-group