psychoric still trying to figure out what this blog is about

Diving diving diving
4Dec/080

Which group(s) am I in?

If you are working in an Active Directory environment and you do utilize it for authentication in your project, this snippet might come handy. It lists the group(s) that current authenticated user belongs to, so you can expand on this to do whatever you need to.

using System.Security.Principal; //do this to save time in typing
 
foreach (IdentityReference ref in WindowsIdentity.GetCurrent().Groups) //get current user group(s)
	Console.WriteLine(ref.Translate(typeof(NTAccount)).ToString()); //translate it to meaningful value
Filed under: Coder's Code No Comments