private static void SetUser(LDAPUserParam param, PropertyCollection propertyCollection, ref LDAPUser user) { user.ID = GetPropertyValue(param.UniqueIDAttribute, propertyCollection); user.FirstName = GetPropertyValue(param.FirstNameAttribute, propertyCollection); user.LastName = GetPropertyValue(param.LastNameAttribute, propertyCollection); user.DisplayName = GetPropertyValue(param.DisplayNameAttribute, propertyCollection); user.Email = GetPropertyValue(param.EmailAttribute, propertyCollection); }
public static LDAPUser GetUser(LDAPUserParam param) { LDAPUser user = new LDAPUser(); DirectoryEntry directoryEntry = new DirectoryEntry(param.Path, param.DomainLoginName, param.Password, AuthenticationTypes.Secure); try { DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry); directorySearcher.Filter = param.UserNameFilter; SearchResult searchResult = directorySearcher.FindOne(); DirectoryEntry userDirectoryEntry = searchResult.GetDirectoryEntry(); PropertyCollection propertyCollection = userDirectoryEntry.Properties; SetUser(param, propertyCollection, ref user); } catch (Exception exception) { user.SetErrorMessage(exception.Message); } return(user); }