当我使用DirectorySearcher调用find.One时,错误消息是什么意思 [英] What is the error message meant when I call find.One using DirectorySearcher
问题描述
我是编写代码来访问AD的新手。我按照AD结构设置:
DC = UAT,DC = COM
OU = ORG
OU =用户和组
OU =系统
OU =团体
CN =管理员
OU =用户
OU =测试
OU =团体
OU =用户
CN = test01
CN = test02
我写了以下示例代码来搜索用户test02,但收到错误:
使用System;
使用System.IO;使用System.DirectoryServices
;
使用System.Configuration;
try
{
DirectoryEntry userEntry = new DirectoryEntry(LDAP:// SERVERIP / OU = ORG,DC = UAT,DC = COM,用户,密码);
DirectorySearcher search = new DirectorySearcher(userEntry);
search.SearchScope = SearchScope.Subtree
//搜索用户test02
search.Filter =(&(objectClass = user)(objectCategory = Person) (sAMAccountName赋= test02));
SearchResult result = search.FindOne(); //在此行失败,抛出异常
if(result == null)
Console.WriteLine(没有要显示的结果);
else
Console.WriteLine(Found result);
}
catch(exception ex)
{
Console.WriteLine(Error:+ ex.Message);
Console.WriteLine(Trece:+ ex.StackTrace);
}
错误:配置系统无法初始化< br />
Trece :在System.Configuration.ClientConfigurationSystem上的System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)< br />
,System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)< br />
。在System.Configuration.PrivilegedConfigurationManager的System.Configuration.ConfigurationManager.GetSection(String sectionName)< br />
的System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)< br />
。 System.DirectoryServices.SearchResultCollection.ResultsEnumerator..ctor(SearchResultCollection结果,String parentUserName,String parentPassword,AuthenticationTypes parentAuthenticationType)中的GetSection(String sectionName)< br />
< br />
at System。 System.DirectoryServices上的DirectoryServices.SearchResultCollection.GetEnumerator()< br />
.DirectorySearcher.FindOne()< br />
你能帮忙并告知我做错了吗?
非常感谢!
Lwang
我发现我的配置文件错误。谢谢!块引用>
Hi,
I'm new in writing code to access AD. I setup following AD structue:
DC=UAT,DC=COM
OU=ORG
OU=Users and Groups
OU=System
OU=Groups
CN=Admins
OU=Users
OU=Test
OU=Groups
OU=Users
CN=test01
CN=test02
I wrote the following sample codes to search for the user test02, but got error:
using System; using System.IO; using System.DirectoryServices; using System.Configuration; try { DirectoryEntry userEntry = new DirectoryEntry("LDAP://SERVERIP/OU=ORG,DC=UAT,DC=COM", user, password); DirectorySearcher search = new DirectorySearcher(userEntry); search.SearchScope = SearchScope.Subtree // Search user test02 search.Filter = "(&(objectClass=user)(objectCategory=Person)(sAMAccountName=test02))"; SearchResult result = search.FindOne(); // Failed at this line, throw exception if (result == null) Console.WriteLine("There is no results to display"); else Console.WriteLine("Found result "); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Trece: " + ex.StackTrace); }
Error: Configuration system failed to initialize<br /> Trece: at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)<br /> at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)<br /> at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)<br /> at System.Configuration.ConfigurationManager.GetSection(String sectionName)<br /> at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)<br /> at System.DirectoryServices.SearchResultCollection.ResultsEnumerator..ctor(SearchResultCollection results, String parentUserName, String parentPassword, AuthenticationTypes parentAuthenticationType)<br /> at System.DirectoryServices.SearchResultCollection.GetEnumerator()<br /> at System.DirectoryServices.DirectorySearcher.FindOne()<br />
Could you help and advise what I did wrong?
Thank you very much!
Lwang解决方案I figured out my configuration file error. Thanks!
这篇关于当我使用DirectorySearcher调用find.One时,错误消息是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!