我正在使用 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
的任何技术? ?
最佳答案
System.DirectoryServices
命名空间针对 Active Directory 进行了优化。它适用于其他 LDAP 服务器 - 有一定的限制。
还有System.DirectoryServices.Protocols
(请参阅 MSDN documentation 和 intro MSDN article )命名空间(.NET 2.0 中的新功能),它更像是一个低级别的 LDAP 实现 - 您需要做更多的工作并编写更多的代码,但它更易于移植并且更可能使用其他 LDAP 存储。
还有System.DirectoryServices.AccountManagement
(请参阅 MSDN documentation )命名空间(.NET 3.5 中的新功能),这是从 .NET 使用 Active Directory 的一种更好、更简单的方法 - 比 S.DS 有很大改进!但据我所知,这只是 Active Directory。
关于.net - 在 .NET Framework 中支持 LDAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699314/