首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-02-21 
C# 获取AD(域用户)的问题在C#代码里有这么一段代码C# codeDirectoryEntry entry new DirectoryEntry(pat

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

热点排行