久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何檢索組中的用戶,包括主要組用戶

How to retrieve Users in a Group, including primary group users(如何檢索組中的用戶,包括主要組用戶)
本文介紹了如何檢索組中的用戶,包括主要組用戶的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 .net 2.0 中工作,需要檢索給定 AD 組的所有用戶.我有以下方法確實返回組的所有成員,但它不返回將傳遞的組作為其主要組的用戶.我需要做什么才能讓這些用戶也包括在內?

I'm working in .net 2.0 and need to retrieve all the users of a given AD group. I have the following method that does return all the members of the group, but it does not return users that have the passed group as their primary group. What do I need to do to get those users included as well?

/// <summary>
/// Gets the group child users.
/// </summary>
/// <param name="parentGroup">The parent group.</param>
/// <returns></returns>
public List<ADUser> GetGroupChildUsers(ADGroup parentGroup)
{
    List<ADUser> list = new List<ADUser>();

    DirectoryEntry entry = GetDirectoryEntry(LdapBaseString);

    DirectorySearcher searcher = new DirectorySearcher(entry);
    searcher.Filter = string.Format("(&(objectCategory=person)(memberOf={0}))", parentGroup.DN);

    searcher.PropertiesToLoad.Add("objectGUID");
    searcher.SizeLimit = MaxReturnCount;

    SearchResultCollection results = searcher.FindAll();

    foreach (SearchResult result in results) {
        Guid guid = new Guid((byte[])result.Properties["objectGUID"][0]);
        list.Add(GetUserByGuid(guid));
    }

    if (list.Count <= 0) {
        return null;
    } else {
        return list;
    }
}

推薦答案

用戶的主要組由用戶的 primaryGroupID 屬性給出.事實上,primaryGroupID 以字符串格式包含主要組的 RID.這就是為什么,我首先獲取您要查找用戶的組的 SID,然后我(錯誤地)計算 RID,并使用包含 RID 的 primaryGroupID 搜索用戶.

The primary group of a user is given by primaryGroupID attribute of a user. In fact primaryGroupID contains the RID of the primary group in a string format. That's why, I first get the SID of the group you are looking for users, then I compute (badly) the RID, and I search for users with a primaryGroupID containing the RID.

/* Connection to Active Directory
 */
DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr");

/* Directory Search for agroup
 */
string givenGrpName = "MonGrpSec"; 
DirectorySearcher dsLookFor = new DirectorySearcher(deBase);
dsLookFor.Filter = string.Format ("(sAMAccountName={0})", givenGrpName);
dsLookFor.SearchScope = SearchScope.Subtree;
dsLookFor.PropertiesToLoad.Add("cn");
dsLookFor.PropertiesToLoad.Add("objectSid");

SearchResult srcGrp = dsLookFor.FindOne();

/* Get the SID
 */
SecurityIdentifier secId = new SecurityIdentifier(srcGrp.Properties["objectSid"][0] as byte[], 0);

/* Find The RID (sure exists a best method)
 */
Regex regRID = new Regex(@"^S.*-(d+)$");
Match matchRID =  regRID.Match(secId.Value);
string sRID = matchRID.Groups[1].Value;

/* Directory Search for users that has a particular primary group
 */
DirectorySearcher dsLookForUsers = new DirectorySearcher(deBase);
dsLookForUsers.Filter = string.Format("(primaryGroupID={0})", sRID);
dsLookForUsers.SearchScope = SearchScope.Subtree;
dsLookForUsers.PropertiesToLoad.Add("cn");

SearchResultCollection srcUsers = dsLookForUsers.FindAll();

foreach (SearchResult user in srcUsers)
{
  Console.WriteLine("{0} is the primary group of {1}", givenGrpName, user.Properties["cn"][0]);
}

這篇關于如何檢索組中的用戶,包括主要組用戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Asp.net System.Web.HttpContext.Current.Session null in global.asax(Asp.net System.Web.HttpContext.Current.Session 在 global.asax 中為 null)
Caught exception is null itself !(捕獲的異常本身為空!)
Why is it Valid to Concatenate Null Strings but not to Call quot;null.ToString()quot;?(為什么連接空字符串有效但調用“null.ToString()無效?)
主站蜘蛛池模板: 综合在线视频 | 91成人精品 | 日韩精品久久久久久 | 夜夜久久| 精品一区二区电影 | 亚洲久久| 成人国产一区二区三区精品麻豆 | 久草新视频 | 久久久精| 欧美在线视频网 | 久久精品亚洲 | 一区二区视频在线 | 久久久精品 | 亚洲人免费视频 | 成人免费视频网站在线观看 | 久草a√ | 亚洲男人网 | 天天综合网7799精品 | 精品成人佐山爱一区二区 | 成人午夜精品 | 激情影院久久 | 草久久 | 一区二区三区免费看 | 91看片在线观看 | 日韩精品免费一区 | 夏同学福利网 | 99久久免费精品国产免费高清 | 欧美日日 | 蜜桃av一区二区三区 | 午夜电影在线播放 | 国产一区二区不卡 | av大片 | 91在线影院| 精品久久久一区 | 精品免费国产一区二区三区 | 91资源在线观看 | 一级黄色片在线免费观看 | 国产在线观看一区二区三区 | 成人午夜av | 久久久久亚洲av毛片大全 | 波多野结衣中文字幕一区二区三区 |