我正在连接到 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 目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!