读书人

C# 获取AD(域用户)的有关问题

发布时间: 2012-02-21 16:26:23 作者: rapoo

C# 获取AD(域用户)的问题
在C#代码里有这么一段代码

C# code
DirectoryEntry entry = new DirectoryEntry(path);DirectorySearcher searcher = new DirectorySearcher(entry);searcher.Filter = "(objectClass=*)";searcher.PropertiesToLoad.Clear();SearchResultCollection searchResultCollection = searcher.FindAll();foreach (SearchResult result in resultCollection)            {if ([color=#FF0000]result.Properties.Contains("samaccountname"))[/color]                {                    ResultPropertyValueCollection resultValue = result.Properties["samaccountname"];                    if (resultValue != null && resultValue.Count > 0 && resultValue[0] != null)                    {                        userName = resultValue[0].ToString();                    }                }}


请问红色那部分表示的是什么意思,获取的是什么的属性?AD里的属性么?

[解决办法]
result.Properties的类型是ResultPropertyCollection
ResultPropertyCollection.Contains:
Determines whether the property that has the specified name belongs to this collection.
[解决办法]
就是判断result.Properties中是否有名字为samaccountname的propery
[解决办法]
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679635(v=vs.85).aspx

读书人网 >C#

热点推荐