group membership check in c#
Wed, Aug 23, 2006It’s pretty easy to check if the active user is a member of a group. There are a couple of ways to do it, some of which are actually more work. The work intensive ways all involve using the DirectoryService to query Active Directory for the information. While thats nice, its not the easiest path. Check this out:
WindowsIdentity mid = WindowsIdentity.GetCurrent();
WindowsPrincipal mpri = new WindowsPrincipal( mid );
if(!mpri.IsInRole(“BUILTIN\Administrators”))
{
// havock ensues
}
System.Security.Principal.WindowsPrincipal is the way to go.