简体   繁体   中英

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. 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. But i just want 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 ; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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