DirectoryEntry domain=new DirectoryEntry(ladpPath, uName, pwd);
search.SearchScope = SearchScope.Subtree;
search.Filter = "(objectclass=User)";
SearchResult result = search.FindOne();
IADsUser iu = (IADsUser)result.GetDirectoryEntry().NativeObject;
List
foreach (IADsGroup item in (IEnumerable)iu.Groups())
rv.Add(item.Name.Split('=')[1]);
//方法二(ldap path 不包含使用者名稱)
DirectoryEntry domain=new DirectoryEntry(ladpPath, uName, pwd);
search.SearchScope = SearchScope.Subtree;
search.Filter = string.Format("(&(objectclass=User)(CN={0})",uName);
SearchResult result = search.FindOne();
IADsUser iu = (IADsUser)result.GetDirectoryEntry().NativeObject;
List
foreach (IADsGroup item in (IEnumerable)iu.Groups())
rv.Add(item.Name.Split('=')[1]);
-------------------------------------
使用IADsUser的Groups取得User的Groups
注意:此方法取得的Groups並不包含PrimaryGroup
沒有留言:
張貼留言