我正在尝试使用此行查询广告
DirectoryEntry de = null;
SearchResult results = null;
de = new DirectoryEntry();
//geting the result FROM ad
de.Path = dr.manager;
de.AuthenticationType = AuthenticationTypes.Secure;
DirectorySearcher search = new DirectorySearcher(de);
search.Filter = string.Format("(objectClass={0})",'*');
search.PropertiesToLoad.Add("IsraelID");
results = search.FindOne();
de = results.GetDirectoryEntry();
但我在 findone() 中遇到异常
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
最佳答案
未指定的错误意味着您的 LDAP 路径缺少 LDAP 协议(protocol)标识符。 确保您的路径包含大写的 LDAP 协议(protocol)标识符。
例子:
DirectoryEntry de = null;
SearchResult results = null;
de = new DirectoryEntry();
// Assuming your domain dns name is treyresearch.net
de.Path = "LDAP://servername/CN=users,DC=treyresearch,DC=net";
de.AuthenticationType = AuthenticationTypes.Secure;
de.Username = "treyresearch\\Administrator";
de.Password = "P@$$W0rd";
DirectorySearcher search = new DirectorySearcher(de);
search.Filter = string.Format("(objectClass={0})",'*');
search.PropertiesToLoad.Add("IsraelID");
results = search.FindOne();
de = results.GetDirectoryEntry();
希望这对您有所帮助。
关于c# - 事件目录 findone() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7892655/