Directory Services
C#
1
Posts
1
Posters
0
Views
1
Watching
-
I am needing to get AD information from a user logon name like AEM\jdixon Im using this for a website to authenticate people to get their Division, First and Last name automatically without them having to sign in or anything. This is what I have:
using (DirectoryEntry root = new DirectoryEntry()) { root.Username = username; root.Password = password; root.Path = LDAPPath; using (DirectorySearcher searcher = new DirectorySearcher()) { searcher.SearchRoot = root; searcher.SearchScope = SearchScope.Subtree; searcher.Filter = "(objectClass=user)"; searcher.PropertiesToLoad.Add("msDS-PrincipalName"); seacher.PropertiesToLoad.Add("divison"); SearchResultCollection results = searcher.FindAll(); StringBuilder summary = new StringBuilder(); foreach (SearchResult result in results) { foreach (string propName in result.Properties.PropertyNames) { foreach (string s in result.Properties\[propName\]) { summary.Append(" " + propName + ": " + s + "\\r\\n"); } } summary.Append("\\r\\n"); } textBoxResults.Text = summary.ToString(); } }
Now I got this from someone else on here that I seen in an article. But I also have my book here and I'm not seeing what I want to do. See in ASP.net you can get their Windows Logon name simple right? Which would pull (lets use mine for example) AEM\JDIXON So now that I have AEM\JDIXON, I want to search AD (first to make sure it exist) and if it exist I want it to pull what DIVISON and the First and Last name. This is for a ticket application.