title: Active directory access and IIS Authetication method issue
body: <p>I have an intranet application that authenticates users against active directory. In general it works fine when testing locally(i.e. from my dev machine using VS 2017) or running it off of IIS in app server ("Browse *:80") until I try to access it using its URL from my local machine. Then whatever user id I use to get user's detail info, nothing is displayed.</p>
  
  <p>Also, this app is to be accessible to users in certain groups so application checks logged in user's group membership.</p>
  
  <p>Here is how I have it set up in IIS and different scenarios I tested with:</p>
  
  <ul>
  <li>I set authentication to "Windows Authentication", disabled anonymous
  authentication and enabled AS.NET Impersonation. This works fine when
  running from app server using localhost but when trying to access
  from my local machine and supplying user's user id to get his/her
  detail info, no details are displayed (fails to get any info from
  AD). </li>
  <li>If I enable anonymous authentication and set it to "Application Pool    Identity" (i.e. Network Services), it displays my custom
  "Access Denied"    page, presumably because this user is not part of
  allowed group. </li>
  <li>If I enable anonymous authentication and select "Specific User",      supplying my credentials, then everything works fine, from app server or from my local machine, with one caveat: no matter who is accessing the site, it shows my name as logged in user.</li>
  </ul>
  
  <p>I am stumped ad would appreciate some hints.</p>
  
  <p><strong>Update - Added code to get user info</strong></p>
  
  <p>Code to get user's identity:</p>
  
  <pre><code>WindowsIdentity wiUser = WindowsIdentity.GetCurrent();
  string sID = wiUser.Name.ToUpper();
  </code></pre>
  
  <p>Code to get user's AD info:</p>
  
  <pre><code>static string adDomain = "www.xxx.yyy.zzz";
  static string adContainer = "DC=www,DC=xxx,DC=yyy,DC=zzz";
  
  public static DataTable getUserADInfoDT(string sSearchStr)
  {
      DataTable dtResults = new DataTable();
      dtResults.Columns.Add("ID");
      dtResults.Columns.Add("FirstName");
      ...
      dtResults.Columns.Add("Zip");
  
      string adDomain = string.Empty;
      string adContainer = string.Empty;
  
      // create domain context
      PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, adDomain, adContainer);
  
      using (adPrincipalContext)
      {
          // define a "query-by-example" principal 
          UserPrincipal qbeUser = new UserPrincipal(adPrincipalContext);
          qbeUser.SamAccountName = sSearchStr.Trim().ToUpper();
  
          // create principal searcher passing in the QBE principal    
          PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
          PrincipalSearchResult&lt;Principal&gt; psr = srch.FindAll();
  
          // find all matches
          foreach (var found in psr)
          {
              DataRow dr = dtResults.NewRow();
              UserPrincipal up = (UserPrincipal)found;
              DirectoryEntry de = (DirectoryEntry)up.GetUnderlyingObject();
  
              dr["ID"] = de.Properties["SAMAccountName"].Value.ToString().ToUpper(); 
  
              if (de.Properties["givenName"].Value != null) 
                  dr["FirstName"] = de.Properties["givenName"].Value.ToString();
  
              ...
  
              if (de.Properties["postalCode"].Value != null)
                  dr["Zip"] = de.Properties["postalCode"].Value.ToString();
  
              dtResults.Rows.Add(dr);
              //de.Close();
          }
          return dtResults;
      }
  }
  </code></pre>