title: Using current user's SharePoint credentials to gain Active Directory access
body: <p>I'm developing a SharePoint 2010 Web Part (in C#) which needs to pull user data from Active Directory but I'm having trouble using the current SharePoint user's credentials to authenticate with AD. I am using the DirectoryEntry class to get data from AD and it works fine when I hard-code some credentials but I know that's bad practice so I want to avoid it. I've tried a couple of different things like:</p>
  
  <pre><code>new DirectoryEntry("LDAP://" + dc, null, null, AuthenticationTypes.ServerBind | AuthenticationTypes.FastBind);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>new DirectoryEntry("LDAP://" + dc, null, null, AuthenticationTypes.Secure);
  </code></pre>
  
  <p>but they all just throw exceptions. I don't really know what these do but it's what I've managed to find online.</p>
  
  <p>Any help that can point me in the right direction would be greatly appreciated.</p>