We have a group in Active Directory with over 70k user accounts. I need to check whether someone is a member of that group. The code is going to run in a web app with a high volume of concurrent users. I'd prefer to stick to System.DirectoryServices.AccountManagement if possible to reduce the amount of code that's written for this app.
There appear to be 2 general approaches to checking whether someone is a member:
- Use UserPrincipal.IsMemberOf() to get a boolean value indicating membership
- Use UserPrincipal.GetGroups() to get a list of group memberships that I can manually check
I want to avoid the enumerating 70k users to check whether someone is in a group, so option 2 seems to be more efficient on face value. When I go into work I can do some tests against both methods but I wanted to get some info on what these methods are really doing under the covers. Am I on the right track here in my thinking?
One last point about the library I'm using. Can I get better performance if I drop out of System.DirectoryServices.AccountManagement altogether and write my own LDAP queries?