本文介绍了为什么异常“在服务器上找不到对象”进入LDAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用LDAP服务器。我安装了相同的并尝试从LDAP服务器获取证书。
我收到异常在服务器上找不到对象。服务器连接正常。
我的代码如下:
I am using LDAP server. I installed the same and trying to fetch the certificates from LDAP server.
I am getting the exception "No Object Found on Server". The server connection is coming fine.
My code is as below:
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://NESTIT-283:389");
rootEntry.AuthenticationType = AuthenticationTypes.None; //Or whatever it need be
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
string searchString = "(CN = EFTS-CA-TEST)";
var queryFormat = "(&(objectClass=user)(objectCategory=person)(|(SAMAccountName=*{0}*)(cn=*{0}*)(gn=*{0}*)(sn=*{0}*)(email=*{0}*)))";
//searcher.Filter = string.Format(queryFormat, searchString);
searcher.Filter = searchString;//Search how you want. Google "LDAP Filter" for more.
foreach (SearchResult result in searcher.FindAll())
{
Console.WriteLine("account name: {0}", result.Properties["samaccountname"].Count > 0 ? result.Properties["samaccountname"][0] : string.Empty);
Console.WriteLine("common name: {0}", result.Properties["cn"].Count > 0 ? result.Properties["cn"][0] : string.Empty);
}
推荐答案
这篇关于为什么异常“在服务器上找不到对象”进入LDAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!