使用 C# DirectoryServices 访问 Active Directory 时出现问题

发布于 2024-12-04 02:34:02 字数 2986 浏览 1 评论 0原文

  string ldapPath = "ldap://db.debian.org:389/uid=ma,ou=users,dc=debian,dc=org";
            DirectoryEntry dEntry = new DirectoryEntry(ldapPath, null, null, AuthenticationTypes.Anonymous);

            DirectorySearcher search = new DirectorySearcher(dEntry);

            search.Filter = "((objectClass=*))";
            search.FindAll();

我正在使用 C# 表单应用程序中的上述代码。每当我调用 FindAll() 时,我都会收到如下异常。

System.Runtime.InteropServices.COMException 未处理
消息 =“未知错误 (0x80005000)”
源=“System.DirectoryServices”错误代码=-2147463168
堆栈跟踪: 在 System.DirectoryServices.DirectoryEntry.Bind(布尔值 如果失败则抛出) 在 System.DirectoryServices.DirectoryEntry.Bind() 在 System.DirectoryServices.DirectoryEntry.get_AdsObject() 在 System.DirectoryServices.DirectorySearcher.FindAll(布尔值 查找多个) 在 System.DirectoryServices.DirectorySearcher.FindAll() 在 LDAPApp.Form1.button1_Click(Object sender, EventArgs e) 中 H:\Raj\LDAP\LDAPApp\LDAPApp\Form1.cs:第 37 行 在 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 在 System.Windows.Forms.Control.WmMouseUp(Message&m, MouseButtons 按钮,Int32 单击) 在 System.Windows.Forms.Control.WndProc(Message&m) 在 System.Windows.Forms.ButtonBase.WndProc(Message&m) 在 System.Windows.Forms.Button.WndProc(Message&m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd、Int32 消息、IntPtr wparam、IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID、Int32 原因、Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext上下文) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext上下文) 在 System.Windows.Forms.Application.Run(Form mainForm) 在 LDAPApp.Program.Main() 中 H:\Raj\LDAP\LDAPApp\LDAPApp\Program.cs:第 18 行 在 System.AppDomain._nExecuteAssembly(程序集, 字符串[] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile, 证据 assemblySecurity,String[] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象 状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态) 在 System.Threading.ThreadHelper.ThreadStart()
内部异常:

请告诉我我在这里做错了什么。

提前致谢。

  string ldapPath = "ldap://db.debian.org:389/uid=ma,ou=users,dc=debian,dc=org";
            DirectoryEntry dEntry = new DirectoryEntry(ldapPath, null, null, AuthenticationTypes.Anonymous);

            DirectorySearcher search = new DirectorySearcher(dEntry);

            search.Filter = "((objectClass=*))";
            search.FindAll();

I am using the above code from my C# forms application. Whenever i am calling the FindAll() I am getting an exception as below.

System.Runtime.InteropServices.COMException was unhandled
Message="Unknown error (0x80005000)"
Source="System.DirectoryServices" ErrorCode=-2147463168
StackTrace:
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.FindAll()
at LDAPApp.Form1.button1_Click(Object sender, EventArgs e) in
H:\Raj\LDAP\LDAPApp\LDAPApp\Form1.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at LDAPApp.Program.Main() in
H:\Raj\LDAP\LDAPApp\LDAPApp\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Please tell me what am i doing wrong here.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小傻瓜 2024-12-11 02:34:02

LDAP 路径中的 LDAP 协议标识符 (LDAP://) 必须为大写。
如果您以小写形式写入 LDAP 协议标识符,则会收到 0x80005000 错误
代码(未知错误)。以下代码片段应该可以工作:

string ldapPath = "LDAP://db.debian.org:389/uid=ma,ou=users,dc=debian,dc=org";
        DirectoryEntry dEntry = new DirectoryEntry(ldapPath, null, null,  AuthenticationTypes.Anonymous);

DirectorySearcher search = new DirectorySearcher(dEntry);

search.Filter = "((objectClass=*))";
search.FindAll();

希望,这有帮助。

The LDAP protocol identifier (LDAP://) in your LDAP path must be uppercase.
If you write the LDAP protocol identifier in lowercase you get the 0x80005000 error
code (unknown error). The following code snippet should work:

string ldapPath = "LDAP://db.debian.org:389/uid=ma,ou=users,dc=debian,dc=org";
        DirectoryEntry dEntry = new DirectoryEntry(ldapPath, null, null,  AuthenticationTypes.Anonymous);

DirectorySearcher search = new DirectorySearcher(dEntry);

search.Filter = "((objectClass=*))";
search.FindAll();

Hope, this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文