title: How best to recursively query AD Group membership in ASP.NET (using vb)
body: <p>I'm trying to find the simplest way to query Active Directory, in one of two ways:</p>
  
  <ol>
  <li><p>Given an AD username, find all the groups (INCLUDING nested groups) that the user is a member of.</p></li>
  <li><p>Given an AD group name, find all the users (including those users in nested groups) that are part of the group. </p></li>
  </ol>
  
  <p>My app is in VB.NET on the v4.0 framework.  I've reviewed suggestions from many different Google search results, some of which utilize LDAP and System.DirectoryServices.DirectorySearcher (which I'm thinking might be the best route).</p>
  
  <p>But I'm spinning my wheels and am looking for code samples.</p>
  
  <p>Thank you.</p>
  
  <p>UPDATE:</p>
  
  <p>I've got these pieces in place:</p>
  
  <p><code>&lt;add assembly="System.DirectoryServices, Version=3.5.0.0, etc."/&gt;</code></p>
  
  <p><code>&lt;add namespace="System.DirectoryServices.AccountManagement" /&gt;</code> or <code>Imports System.DirectoryServices.AccountManagement</code></p>
  
  <p>and on this line of code:</p>
  
  <p><code>Dim ctx As New PrincipalContext(ContextType.Domain)</code></p>
  
  <p>I still get this error:  <em>Type 'PrincipalContext' is not defined</em></p>
  
  <p>When you mention the "using statement," I assume you meant that I need to reference this namespace.  Or did you mean I should do something like this?</p>
  
  <p><code>Using ctx As New PrincipalContext(ContextType.Domain)</code></p>