Link to home
Start Free TrialLog in
Avatar of DigiFoto
DigiFoto

asked on

ActiveDirectory programming is not recurning anything

Hi folks.  We are trying to do some ActiveDirectory programming, see the code snip below.  The purpose is by entering a GroupName, we want to list the members of that group.  It works fine on local development machine with IIS running, but it returns nothing when we pushed it to the web server.  Any idea what is going on?  Thanks.

      protected void Page_Load(object sender, EventArgs e)
      {
         GetMembers();
      }

      private void GetMembers()
      {
         try
         {
            DirectoryEntry ent = new DirectoryEntry("GC://cdc.gov/DC=cdc,DC=gov");
            DirectorySearcher srch = new DirectorySearcher(ent);
            srch.Filter = "(CN=DLS_Informatics_Team)"; //DLS_Informatics_Team: the group name.  Manually put in for development purposes.

            SearchResultCollection coll = srch.FindAll();

            ArrayList userNames = new ArrayList();
            foreach (SearchResult rs in coll)
            {
               ResultPropertyCollection resultPropColl = rs.Properties;
               foreach (Object memberColl in resultPropColl["member"])
               {
                  DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://cdc.gov/" + memberColl);
                  System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties;
                  object obSam = userProps["sAMAccountName"].Value;
                  object obUserName = userProps["displayname"].Value;
                 
                  if (obSam !=null)
                  {
                     Response.Write(obSam.ToString() + " - " + obUserName.ToString() + "<br>");
                  }
               }
            }
         }
         catch (Exception ex)
         {
            Response.Write(ex.Message);
         }
      }
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial