title: How to get AD User Groups for user in Asp.Net?
body: <p>I need to be able to get a list of the groups a user is in, but I need to have one/some/all of the following properties visible:</p>
  
  <ul>
  <li>distinguishedname</li>
  <li>name</li>
  <li>cn</li>
  <li>samaccountname</li>
  </ul>
  
  <p>What I have right now returns some sort of name, but not any of the ones above (the names seem close, but don't all match correctly.  This is what I am using:</p>
  
  <pre><code>ArrayList groups = new ArrayList();
  foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
      groups.Add(group.Translate(typeof(System.Security.Principal.NTAccount)));
  </code></pre>
  
  <p>Like I said, the above works, but will not get me the proper names I need for my program (the ones specified above).  I need this to be able to match up with the list I get while calling all of the groups in my domain:</p>
  
  <pre><code>DirectoryEntry dirEnt = new DirectoryEntry("LDAP://my_domain_controller");
  DirectorySearcher srch = new DirectorySearcher(dirEnt);
  srch.Filter = "(objectClass=Group)";
  var results = srch.FindAll();
  </code></pre>