Last post May 27, 2017 05:12 AM by EvenMa
May 12, 2017 07:52 AM|aiverkeith|LINK
I have a project to create a web app to connect on our active directory. The first objective is to able to search for an account using first name, last name and user logon name. Can someone help me? I don't know where to start. When searching on google I
came across LDAP. I'm very new to Visual Studio and web applications but I have basic knowledge on programming and willing to learn.
May 12, 2017 09:01 AM|PatriceSc|LINK
https://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement(v=vs.110).aspx and in particular https://msdn.microsoft.com/en-us/library/bb344891(v=vs.110).aspx and
http://stackoverflow.com/questions/10249205/search-a-user-login-id-by-first-name-and-last-name to search for users.
May 15, 2017 07:27 AM|aiverkeith|LINK
Thanks for this PatriceSc! I really appreciate your answer.
May 15, 2017 09:19 AM|Zhi Lv - MSFT|LINK
According to your description, the following code is how to get the accounts and it's properties, it might help you.
using (var context = new PrincipalContext(ContextType.Domain, "yourdomain.com"))
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
foreach (var result in searcher.FindAll())
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value);
Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
You can also refer following links, they have more operation with active directory's example.
May 23, 2017 07:12 AM|aiverkeith|LINK
Thanks for this too Zhi Lv! but I'm stuck on the query filter. I want to query using Employee ID but I don't know what to put to search using textbox. This is the code.
adSearcherLdap.Filter = "(&(objectClass=user)(objectCategory=person)(wWWHomePage=queryTextBox.Text)";
I don't know what to put at wWWHomePage and it seems I can't find the solution for this on google.
May 27, 2017 05:12 AM|EvenMa|LINK
If you want to filter user by account ,you could write like the following code:
adSearcherLdap.Filter = "(&(objectClass=user)(objectCategory=person)(SAMAccountName="+account+")";
In your case, might you could write like the following code:
adSearcherLdap.Filter = "(&(objectClass=user)(objectCategory=person)(wWWHomePage="+queryTextBox.Text+")";
For more examples about LDAP filters ,you could refer to the following code:
If you have any other questions, please feel free to contact me any time.