.NET Framework 中对 LDAP 的支持

发布于 2024-12-23 12:30:18 字数 449 浏览 2 评论 0原文

我正在使用 System.DirectoryServices 查询活动目录以在 winforms 应用程序中验证/获取用户信息。如下所示:

var path = "LDAP://" + domain;
var entry = new DirectoryEntry(path);
DirectorySearcher myDirectorySearcher = new DirectorySearcher(entry);
var filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", username);
myDirectorySearcher.Filter = filter;  

我只能在公司的 Active Directory 上测试此代码。这适用于任何支持 LDAP 的技术吗?

I'm using System.DirectoryServices to query active directory to authenticate/fetch users' info in a winforms appliation. Something like below:

var path = "LDAP://" + domain;
var entry = new DirectoryEntry(path);
DirectorySearcher myDirectorySearcher = new DirectorySearcher(entry);
var filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", username);
myDirectorySearcher.Filter = filter;  

I can only test this code on company's Active Directory. Is this going to work on any technology that supports LDAP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人如玉 2024-12-30 12:30:18

System.DirectoryServices 命名空间针对 Active Directory 进行了优化。它可以与其他 LDAP 服务器一起工作 - 但有一定的限制。

还有 System.DirectoryServices.Protocols (请参阅 MSDN 文档MSDN 简介文章)命名空间(.NET 2.0 中的新功能),这更多的是低级 LDAP 实现 - 您需要做更多工作并编写更多代码,但它更可移植并且更可能与其他 LDAP 存储一起使用。

还有System.DirectoryServices.AccountManagement(请参阅MSDN 文档< /a>) 命名空间(.NET 3.5 中的新功能),这是使用 .NET 中的 Active Directory 的一种更好、更简单的方法 - 比 S.DS 的东西有了很大的改进!但据我所知,这只是 Active Directory。

The System.DirectoryServices namespace is optimized for Active Directory. It will work against other LDAP servers - with certain limitations.

There's also the System.DirectoryServices.Protocols (see MSDN documentation and intro MSDN article) namespace (new in .NET 2.0) which is more of a low-level LDAP implementation - you need to do more work and write more code, but it's more portable and more likely to work with other LDAP stores.

There's also the System.DirectoryServices.AccountManagement (see MSDN documentation) namespace (new in .NET 3.5) which is a much nicer and simpler approach to using Active Directory from .NET - much improved over the S.DS stuff! But this is Active Directory only as far as I can tell.

猫弦 2024-12-30 12:30:18

您应该将过滤器更改为如下所示:

var filter = string.Format("(&(objectCategory={0})(objectClass={1})(sAMAccountName={2}))", "person ", "user", username);

不过,这通常不适用于任何 LDAP 目录。例如,sAMAccountName 是 AD 特定属性。

You should change the filter to look like this:

var filter = string.Format("(&(objectCategory={0})(objectClass={1})(sAMAccountName={2}))", "person", "user", username);

This isn't going to generically work with any LDAP directory, though. sAMAccountName, for example, is an AD specific attribute.

幸福%小乖 2024-12-30 12:30:18

上次我尝试在 Novell 网络中使用 system.directoryservices 时,它完全不起作用,到处都抛出异常。抱歉,我无法更具体地说明版本号。

The last time I tried to use system.directoryservices with a Novell network it just completely didn't work, exceptions were just thrown all over the place. Sorry I can't be more specific with version numbers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文