确定用户的域在Active Directory搜索结果搜索结果、用户、Active、Directory

2023-09-08 12:24:06 作者:爷ヽ已看破红尘

可能重复:   How我可以得到域\用户从AD的DirectoryEntry?

下面是我现在所拥有的:

Here is what I have right now:

DirectoryEntry de = new DirectoryEntry("LDAP://" + domain);
SearchResult result;
DirectorySearcher search = new DirectorySearcher(de);
search.Filter = String.Format("(cn={0})", groupName);
search.PropertiesToLoad.Add("member");
result = search.FindOne();

注意组名(其中传递到方法重新presenting该组的名称来搜索参数)可以是一个通用组,这意味着它可能包含来自其他域的帐户。

Note that groupName (which a parameter passed into the method representing the name of the group to search in) can be a universal group, which means it might contain accounts from other domains.

哪个属性在 searchresultcollection 我应该用您的账户起源,甚至更好的是有一个网页,有所有属性可用的列表中选择域这个特殊的收藏?

Which property in the searchresultcollection should I use to find the domain the account originates from, or even better is there a webpage that has a list of all the properties available to this particular collection?

推荐答案

任何AD对象的的distinguishedName 属性应始终包含完整的LDAP兼容的路径,该对象,如

The distinguishedName property of any AD object should always contain the full LDAP compatible path to that object, e.g.

CN=John Doe,OU=Marketing,OU=IntlSales,DC=YourMegaCorp,DC=com

根据该DN你可以计算出域( DC = YourMegaCorp,DC = COM ),这个用户是从哪里来的。我不认为有任何其他的(默认)AD属性,会给你刚才的域名,但 - 你需要破解和分析的DN得到你需要的信息

Based on that DN you can figure out the domain (DC=YourMegaCorp,DC=com) that this user came from. I don't think there's any other (default) AD attribute that would give you just the domain, though - you'll need to "crack and parse" that DN to get the info you need.