首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用System.DirectoryServices在System.DirectoryServices上搜索LDAP用户数据?

如何使用System.DirectoryServices在System.DirectoryServices上搜索LDAP用户数据?
EN

Stack Overflow用户
提问于 2022-08-05 10:31:46
回答 1查看 206关注 0票数 0

我连接在System.DirectoryServices的LDAP服务器上,并将用户绑定到他的凭据中,但现在我想获取他自己的数据,如邮件、电话号码等。如何在System.DirectoryServices中实现这一点?到现在为止我都是这么做的?

代码语言:javascript
复制
LdapDirectoryIdentifier id= new LdapDirectoryIdentifier("localhost", 10389);
                LdapConnection conn=
                    new LdapConnection(id);
                var username= text_field_for_username.Text;
                var pass= text_field_for_pass.Text;
                conn.AuthType = AuthType.Basic;
                conn.SessionOptions.ProtocolVersion = 3;
                NetworkCredential param= new NetworkCredential("uid="+username+",ou=employees,dc=company,dc=com",pass);
conn.Bind(param);

而且起作用了。现在,如何使用System.DirectoryServices获取经过身份验证的用户的数据?顺便说一句,我知道不存在用户的可能性,为此我将添加“尝试和捕捉”块。

EN

回答 1

Stack Overflow用户

发布于 2022-08-05 16:39:20

基本上,您可以使用DirectoryServices SearchRequestSearchResponse执行以下操作

代码语言:javascript
复制
// ...

// Just for convenience 
conn.Credential = new NetworkCredential(userDN, userPass);
conn.Bind();

// The attributes to read, use "*" to request all user attributes.
var attr = new[] { "uid", "displayName", "mail" };

// Set userDN as basedn and search scope to Base to search user's own entry (filter is null)
SearchRequest req = new SearchRequest(userDN, (string) null, SearchScope.Base, attr);
var response = (SearchResponse) conn.SendRequest(req);

var entry = response.Entries[0];
// ... 

见文档:SearchRequestSearchResponse

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73248351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档