简体   繁体   English

如何获取SearchResultEntry的用户名

[英]how to get the username of a SearchResultEntry

I am implementing the dirSync polling for changes within active directory, using ldap. 我正在使用ldap为活动目录中的更改实现dirSync轮询。 It is working fine however i would like to get the username attribute ("samaccountname") associated with the SearchResultEntry object in addition to the changes that would be detected 它工作正常,但我想获得与SearchResultEntry对象关联的用户名属性(“samaccountname”)以及将被检测到的更改

You must request the attributes as part of the search request. 您必须在搜索请求中请求属性。 If the attribute(s) you desire are transmitted to the server as past of the search request, and if the server allows the authentication state of the connection to retrieve those attributes, then those attributes will be included in the search result. 如果您希望的属性作为搜索请求的过去传输到服务器,并且服务器允许连接的身份验证状态检索这些属性,那么这些属性将包含在搜索结果中。 For more information, see LDAP: Programming Practices and Using ldapsearch . 有关更多信息,请参阅LDAP:编程实践使用ldapsearch The latter refers to the command-line ldapsearch tool, but the concepts are valid for any language. 后者指的是命令行ldapsearch工具,但这些概念对任何语言都有效。

SearchResult result; // this would've been defined elsewhere
if(result != null)
{
    DirectoryEntry entry = result.GetDirectoryEntry();
    string name = (string)entry["SAMAccountName"].Value;
}

This will allow you to get the name from the user and stores it in name and assumes you have a SearchResult named result already populated from some search on the directory. 这将允许您从用户获取名称并将其存储在名称中,并假定您已从目录上的某些搜索填充了SearchResult命名结果。

Edit: I realized that this isn't what you asked for, you are using SearchResultEntry and not the DirectoryServices.SearchResult. 编辑:我意识到这不是你要求的,你使用的是SearchResultEntry而不是DirectoryServices.SearchResult。 I'll leave this here just in case it may help but I apologize for not properly reading the original question. 我会留在这里以防万一它可能会有所帮助,但我为没有正确阅读原始问题而道歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM