I'm really new to C# so forgive my ignorance. I need to test if a user (DOMAIN\username) is in a particular group, and yes, this includes nested groups.
I have found that WindowsPrincipal.IsInRole()
works fantastic, when dealing with the current logged-in user. That isn't the case for me though. I need to be able to pass in an arbitrary DOMAIN\username or UPN (I'll do whichever is easiest to implement), and get back true/false if they are a member of group X, even if they are only indirect members of group X (e.g: user is member of group Y, and group Y is member of group X).
I've looked at WindowsIdentity
, and maybe it's being new to C#, but I just didn't see a way to do something like WindowsIdentity("MYDOMAIN\User1")
. Well, I did, but never got anywhere close to getting it to work.
Using C#, given a DOMAIN\username, which will not be the current logged-in user, how can I determine if they are a member of DOMAIN\group ?