How to know if my DirectoryEntry is really connected to my LDAP directory?(如何知道我的 DirectoryEntry 是否真的连接到我的 LDAP 目录?)
问题描述
我正在连接到 C# 中的 LDAP 目录,因此我使用了 DirectoryEntry 类.
I'm connecting to a LDAP directory in C#, so I've used the DirectoryEntry class.
当您使用地址、登录名和密码执行new DirectoryEntry"时,它应该连接到 LDAP 目录.
When you do the "new DirectoryEntry" with address, login, and password it is supposed to connect to the LDAP directory.
然而,即使连接不工作,它也毫无问题地返回,并且设置了目录项变量.
However, even if the connection didn't work, it returns without problem, and the directoryentry variable is set.
所以我知道我的连接真的打开了吗?现在,我正在使用一个非常非常丑陋的 hack :我放置了一个if(mydirectory.SchemaEntry)",如果没有建立连接,它会生成一个异常,因为 DirectoryEntry 的一些成员,例如 SchemaEntry,如果连接失败,则不设置.但是 1:这在丑陋的尺度上必须是 11/10 2:在失败之前需要很多时间.
So i do i know my connection is really opened ? Right now, I'm using a very very ugly hack : i put a "if(mydirectory.SchemaEntry)" which generates an exception if the connection wasn't etablished, because some of the members of the DirectoryEntry, such as SchemaEntry, aren't set if the connection failed. But 1:that's gotta be 11/10 on the ugliness scale 2:that takes a lot of time before failing.
那么这样做的好方法是什么?当然,Microsoft 一定提供了一些信息(即使我使用的是 LDAP 目录而不是 Active Directory)来了解我是否真的已连接?
So what is the good way to do this ? Surely, Microsoft must have provided something (even if I'm using a LDAP directory and not an Active Directory) to know if I'm really connected ?
推荐答案
好吧,marc_s 的解决方案与我正在做的差不多(除了我在寻找 SchemaEntry 而不是 NativeObject).但是超时延迟太长(运行查询以填充表单的自动完成值).我想我实际上更喜欢假装连接是打开的并让查询运行.这样,我可以设置自己的更小超时延迟.
Ok so marc_s's solution was approximately what i was doing (except i was looking for SchemaEntry and not NativeObject). But the timeout delay is much too long (the query is run to fill autocompletion values for a form). I think I actually prefer to pretend the connection is open and let the query run. That way, i can set my own, smaller, timeout delay.
这篇关于如何知道我的 DirectoryEntry 是否真的连接到我的 LDAP 目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何知道我的 DirectoryEntry 是否真的连接到我的


基础教程推荐
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- 创建属性设置器委托 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01