title: handling multiple Domains for Active Directory Authentication
body: <p>In my application I have the following method which I pass the AD Username to it (example: Domain1\User1) and try to find the groups that user belongs to in Active Directory.</p>
  
  <pre><code>     public ActionResult Login(string userName)
     {
          PrincipalContext up = new   PrincipalContext(ContextType.Domain);
  
          UserPrincipal users = UserPrincipal.FindByIdentity(up,IdentityType.SamAccountName, userName);
  
          PrincipalSearchResult&lt;Principal&gt; groups = users.GetGroups();
          IEnumerable&lt;string&gt; userGroupList = groups.Select(p =&gt;p.SamAccountName);
          return userGroupList ;
      }
  </code></pre>
  
  <p>The code works perfectly, However I am guessing this code will failto work in an environment where there are multiple domains.
  For example:
  1) User try to login with (<strong>Domain1\User1</strong>) and it will go through,
  2) User try to login with (<strong>Domain2\User2</strong>) the app will try to look for <strong>User2</strong> in <strong>Domain1</strong>, and becasue there is no such user in Domain1 it will fail.</p>
  
  <p>Is this true? if yes, how can I resolve this issue so it will works with multiple domain?</p>