title: Fetching full name from Active Directory using C# doesn't work after deployment
body: <p>I'm fetching a user's full name from the server using the following code:</p>
  
  <pre><code>public string getUserName(int empID)
          {
  
              DirectoryEntry objDirectoryEntry = new DirectoryEntry("LDAP://SOMEDOMAIN.com");
              objDirectoryEntry.AuthenticationType = AuthenticationTypes.Secure;
  
              DirectorySearcher objDirectorySearch = new DirectorySearcher(objDirectoryEntry);
              objDirectorySearch.Filter = "(SAMAccountName=" + empID + ")";
              objDirectorySearch.PropertiesToLoad.Add("displayName");
  
              SearchResult objSearchResult = objDirectorySearch.FindOne();
  
              if (objSearchResult != null)
  
                  return Convert.ToString(objSearchResult.Properties["displayname"][0]);
  
              else
  
                  return "User not found";
  
          }
  </code></pre>
  
  <p>This works perfectly fine on my local machine.</p>
  
  <p>However, after deploying this to the server, it doesn't work at all.</p>
  
  <p>This returns NULL.</p>
  
  <p>As @marc_s suggested I tried using the following code :</p>
  
  <pre><code>public string getUserStackExchange(string empID)
          {
              string fullName = empID;
              // set up domain context using the default domain you're currently logged in 
              using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
              {
                  // find a user
                  UserPrincipal user = UserPrincipal.FindByIdentity(ctx, empID);
  
                  /* or if you're interested in the *currently logged in* user,
                     then you could also use:
                  UserPrincipal user = UserPrincipal.Current;
                  */
  
                  if (user != null)
                  {
                      // get the "DisplayName" property ("Fullname" is WinNT specific)
                      fullName = user.DisplayName;
  
                      // do something here....        
                  }
              }
              return fullName;
          }
  </code></pre>
  
  <p>Same result. Works perfectly fine in local. But it doesn't work after deployment.
  However,If I run the project in Debug mode with breakpoints on, It fetches data perfectly.</p>
  
  <p>Is there something wrong with the code or IIS configuration (I suspect this)?</p>