简体   繁体   English

在ASP.NET C#中仅从ldap获取名称

[英]Get just the name from ldap in asp.net c#

I want to diaplay all the names that match with the user provided name from a directory server using LDAP and bind it to grid view. 我想使用LDAP从目录服务器中显示与用户提供的名称匹配的所有名称,并将其绑定到网格视图。 Am able to achieve this task bt instead of just a name am getting other properties like LDAP://CN=Neha Shetty,OU=Users,OU=MUM,OU=Mumbai,OU=India,OU=APAC,OU=bunt,DC=xxx,DC=com. 能够完成此任务bt而不仅仅是获得名称,而是获得其他属性,例如LDAP:// CN = Neha Shetty,OU = Users,OU = MUM,OU =孟买,OU =印度,OU =亚太,OU =邦特, DC = xxx,DC = com。 But i just want Neha Shetty. 但是我只想要Neha Shetty。 Here is my code 这是我的代码

DirectoryEntry de = new DirectoryEntry("ADConnection");

DirectorySearcher deSearch = new DirectorySearcher(de);

//set the search filter    
deSearch.SearchRoot = de;
String UserName = txt_To.Text;
// deSearch.Filter = "(&(objectCategory=user)(GivenName=*" + UserName + "*))";
deSearch = new DirectorySearcher("(&(objectCategory=user)(Name=*" + UserName + "*))");
//deSearch.SearchScope = SearchScope.Subtree;
string[] arrPropertiesToLoad = { "Surname" };
deSearch.PropertiesToLoad.AddRange(arrPropertiesToLoad);

//  SearchResultCollection sResultColl = deSearch.FindAll();
SearchResultCollection sResultColl;
sResultColl = deSearch.FindAll();

Gridview1.DataSource = sResultColl;
Gridview1.DataBind();
LDAP://CN=Neha Shetty,OU=Users,OU=MUM,OU=Mumbai,OU=India,OU=APAC,OU=bunt,DC=xxx,DC=com

is the distinguished name of the entry, and is always returned in a search result that returns at least one entry. 是条目的专有名称,并且总是在返回至少一个条目的搜索结果中返回。 The distinguished name is used as the primary key for an entry in a directory. 可分辨名称用作目录中条目的主键

Directories do not have properties , directories have attributes which are grouped according to objectClasses into entries ; 目录没有属性 ,目录具有根据objectClasses分组为条目的 属性 ; properties are single-valued attributes might be multi-valued. 属性是单值属性,可能是多值。 The LDAP client must specify which user attributes should be returned as one of the parameters of the search request. LDAP客户端必须指定应将哪些用户属性作为搜索请求的参数之一返回。

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

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