Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IList<string> SetUserInformation()
- {
- string locCode = string.Empty;
- string firstName = string.Empty;
- string lastName = string.Empty;
- string contactInfo = string.Empty;
- string mail = string.Empty;
- string phone = string.Empty;
- string ext = string.Empty;
- IList<string> data = new List<string>();
- string userName, userPassword;
- userName = "Hpd016AspNet";
- userPassword = "asp.net";
- DirectoryEntry entry = new DirectoryEntry("LDAP://us.parker.corp/OU=FCG,DC=us,DC=parker,DC=corp", userName, userPassword);
- DirectorySearcher searcher = new DirectorySearcher(entry);
- searcher.SearchRoot = entry;
- string currentUser = HttpContext.Current.User.Identity.Name;
- currentUser = currentUser.Remove(0, 6);
- searcher.Filter = "(&(objectClass=user)(userPrincipalName=*" + currentUser + "*))";
- searcher.SearchScope = SearchScope.Subtree;
- searcher.PropertiesToLoad.Add("displayName");
- searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
- searcher.PropertiesToLoad.Add("givenname");
- searcher.PropertiesToLoad.Add("sn");
- searcher.PropertiesToLoad.Add("mail");
- searcher.PropertiesToLoad.Add("telephonenumber");
- searcher.PropertiesToLoad.Add("extension");
- SearchResult result = searcher.FindOne();
- if (result != null)
- {
- ResultPropertyCollection props = result.Properties;
- foreach (DictionaryEntry x in props)
- {
- switch (x.Key.ToString().ToLower())
- {
- case "physicaldeliveryofficename":
- locCode = props["physicalDeliveryOfficeName"][0].ToString();
- break;
- case "givenname":
- firstName = props["givenname"][0].ToString();
- break;
- case "sn":
- lastName = props["sn"][0].ToString();
- break;
- case "mail":
- mail = props["mail"][0].ToString();
- break;
- case "telephonenumber":
- phone = props["telephonenumber"][0].ToString();
- break;
- case "extension":
- ext = props["extension"][0].ToString();
- break;
- case "displayname":
- break;
- default:
- break;
- }
- }
- }
- data.Add(locCode);
- data.Add(firstName);
- data.Add(lastName);
- contactInfo = mail + " " + phone + " " + ext;
- data.Add(mail);
- data.Add(phone + " " + ext);
- data.Add(contactInfo);
- return data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement