問題描述
我正在連接到 C# 中的 LDAP 目錄,因此我使用了 DirectoryEntry 類.
I'm connecting to a LDAP directory in C#, so I've used the DirectoryEntry class.
當(dāng)您使用地址、登錄名和密碼執(zhí)行new DirectoryEntry"時,它應(yīng)該連接到 LDAP 目錄.
When you do the "new DirectoryEntry" with address, login, and password it is supposed to connect to the LDAP directory.
然而,即使連接不工作,它也毫無問題地返回,并且設(shè)置了目錄項變量.
However, even if the connection didn't work, it returns without problem, and the directoryentry variable is set.
所以我知道我的連接真的打開了嗎?現(xiàn)在,我正在使用一個非常非常丑陋的 hack :我放置了一個if(mydirectory.SchemaEntry)",如果沒有建立連接,它會生成一個異常,因為 DirectoryEntry 的一些成員,例如 SchemaEntry,如果連接失敗,則不設(shè)置.但是 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.
那么這樣做的好方法是什么?當(dāng)然,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).但是超時延遲太長(運行查詢以填充表單的自動完成值).我想我實際上更喜歡假裝連接是打開的并讓查詢運行.這樣,我可以設(shè)置自己的更小超時延遲.
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.
這篇關(guān)于如何知道我的 DirectoryEntry 是否真的連接到我的 LDAP 目錄?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!