Friday, 15 May 2015

Active Directory not finding all users in C# -


I have some code that asks the Active Directory to verify the existence of the user. I am trying to verify a long list of approximately 1300 IDs, I have a user account (Eddie from LINQ, Directory Search (with and without a directory entry) and a directory entry, which is linked to WinNT: // path) Have tried several ways to verify. Each time it will come back and say that many users are not present. If I code code in my user id code and execute it personally, then it validates the existence. If I try and do it in a forte loop, then I get many wrong negative.

Here is the code that I am currently using.

  Fixed string [] userIDs = new string [] "user1", "user2", " User 3 "," User 4 "," User 5 "," User 6 "," User 7 "," User 8 "...," User 1300 "}; & Lt; String & gt; NonExistingUsers = New List & lt; String & gt; (); & Lt; String & gt; Existing user = new list & lt; String & gt; (); Foreach (string in userIDs) {DirectorySearcher search = new DirectorySearcher (); Search.Filter = String.Format ("(SAMAccountName = {0})", s); Search.PropertiesToLoad.Add ("cn"); DirectorySearcher ds = new DirectorySearcher (de, "(and (objectClass = user) (cn =" + s + "))," New string [] {"name"}, SearchScope.Subtree); Search Result Collection Results Collection = D. Fidel (); SearchResult Results = search.FindOne (); If (result! = Zero) current user Add (s); Other non-current users Add (s); }  

Any suggestions or reasons why I am getting wrong negatives?

Some of the things:

  • First of all, Try using "anr =" (ambiguous name resolution) in your LDAP filter - it searches for many name-related features and makes easy search userID not part of the actual "normal name" (cn = user1) Maybe

  • Secondly, use object content instead of object - object cabant alone valuable and sequential And

  • In the third place: you are why call first stage.Films () and then Kfndon () on the next line? In fact it does not seem necessary ....

  • In fact, only for backward compatibility and if you need to deal with local computer accounts - try to avoid it Whenever possible, it displays very little properties compared to LDAP

  • Static String [] UserIDs = New string [] "User1", "User2", "User3", "User4", "User 5", "User6", "User 7", "Users Guy 8 "...," User 1300 "}; DirectoryEntry searchRoot = New directoryInterity ("LDAP: // cn = User, DC = YourComp, DC = com"); & Lt; String & gt; NonExistingUsers = New List & lt; String & gt; (); & Lt; String & gt; Existing user = new list & lt; String & gt; (); Foreach (string in userIDs) {DirectorySearcher search = new DirectorySearcher (searchRoot); Search.SearchScope = SearchScope.Subtree; Search.Filter = string.Format ("(and (object category = person) (anr = {0}))", s); Search Result Collection Results Collection = D. Fidel (); If (result! = Null & amp; result result.Count & gt; 0) existing user. Add (s); Other non-current users Add (s); }

    Is this work in your scenario ??

    In addition, if you use .NET 3.5 or later, things are very easy - see:


No comments:

Post a Comment