当我使用DirectorySearcher调用find.One时,错误消息是什么意思 [英] What is the error message meant when I call find.One using DirectorySearcher

查看:77
本文介绍了当我使用DirectorySearcher调用find.One时,错误消息是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是编写代码来访问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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆