如何知道我的 DirectoryEntry 是否真的连接到我的 LDAP 目录?

How to know if my DirectoryEntry is really connected to my LDAP directory?(如何知道我的 DirectoryEntry 是否真的连接到我的 LDAP 目录?)
本文介绍了如何知道我的 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 目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to determine the type (AD User vs. AD Group) of an account?(如何确定帐户的类型(AD 用户与 AD 组)?)
How to resolve quot;The server does not support the control. The control is critical.quot; Active Directory error(如何解决“服务器不支持控件.控制至关重要.活动目录错误)
How to authenticate users with a customer#39;s (remote) active directory server(如何使用客户的(远程)活动目录服务器对用户进行身份验证)
Add member to AD group from a trusted domain(将成员从受信任的域添加到 AD 组)
How to retrieve Users in a Group, including primary group users(如何检索组中的用户,包括主要组用户)
Active Directory: DirectoryEntry member list lt;gt; GroupPrincipal.GetMembers()(Active Directory:DirectoryEntry 成员列表 lt;gt;GroupPrincipal.GetMembers())