title: How to get the current user's Active Directory details in C#
body: <p>I am working on an C# and ASP.Net application, that uses Windows Authentication. </p>
  
  <p>i.e. in Web.config:</p>
  
  <pre><code>&lt;system.web&gt;
      &lt;authentication mode="Windows" /&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>I want to get details for the current user (full name, email address, etc) from Active Directory.</p>
  
  <hr>
  
  <p>I can get their pre Windows 2000 user login name (eg: <code>SOMEDOMAIN\someuser</code>) by using</p>
  
  <pre><code>string username = HttpContext.Current.Request.ServerVariables["AUTH_USER"];
  </code></pre>
  
  <p>I've worked out the LDAP query for the user, using their current login name (not their pre Windows 2000 user login name):</p>
  
  <pre><code>DirectorySearcher adSearch = new DirectorySearcher(
          "(userprincipalname=someuser@somedomain.com.au)");
  SearchResult adSearchResult = adSearch.FindOne();
  </code></pre>
  
  <p>However, I don't know how to either search AD for the user using their pre W2K login name, or get their login name in the 'someuser@somedomain.com.au' format.</p>
  
  <p>Any ideas?</p>