啊。LDAP。如果您使用的是.Net framework
3.5或更高版本,我强烈建议您使用System.DirectoryServices.AccountManagement命名空间。这使事情变得 如此
容易得多。
public void AddUserToGroup(string userId, string groupName) { try { using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "COMPANY")) { GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName); group.Members.Add(pc, IdentityType.UserPrincipalName, userId); group.Save(); } } catch (System.DirectoryServices.DirectoryServicesCOMException E) { //doSomething with E.Message.ToString(); } }public void RemoveUserFromGroup(string userId, string groupName){ try { using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "COMPANY")) { GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName); group.Members.Remove(pc, IdentityType.UserPrincipalName, userId); group.Save(); } } catch (System.DirectoryServices.DirectoryServicesCOMException E) { //doSomething with E.Message.ToString(); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)