如何知道我的DirectoryEntry真的连接到我的LDAP目录? [英] How to know if my DirectoryEntry is really connected to my LDAP directory?

查看:936
本文介绍了如何知道我的DirectoryEntry真的连接到我的LDAP目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接到在C#中的LDAP目录,所以我使用的DirectoryEntry类。

I'm connecting to a LDAP directory in C#, so I've used the DirectoryEntry class.

当你做了新的DirectoryEntry与地址,登录名和密码,它应该连接到LDAP目录。

When you do the "new DirectoryEntry" with address, login, and password it is supposed to connect to the LDAP directory.

然而,即使在连接不工作时,它返回没有问题,且的DirectoryEntry变量设置

However, even if the connection didn't work, it returns without problem, and the directoryentry variable is set.

所以我知道我的连接被真正打开?现在,我使用的是一个非常非常丑陋的黑客:我把如果(mydirectory.SchemaEntry),它会产生一个例外,如果连接不etablished,因为有些的DirectoryEntry的成员,如SchemaEntry,对吧T设置,如果连接失败。但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.

那么,什么是好办法做到这一点?当然,微软必须提供的东西(即使我使用的是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)。但超时延迟太长(运行查询,以填补自动完成值的一种形式)。我想,我居然preFER至pretend连接打开,让查询运行。这样的话,我可以把我自己的,更小,超时延迟。

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆