Link to home
Start Free TrialLog in
Avatar of sqlagent007
sqlagent007Flag for United States of America

asked on

how to connect to query AD if the web server is not on the domain

I have the following code that works great in DEV because the DEV server is on the domain. However when I deploy the files to the web server (not on the domain), my page does not work. Do I put the connection for active directory in the web.config file, or does it get embedded into the c# (sorry, I am new to web development)?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.Text;
using System.Collections;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;


namespace MasterPageTst.SA
{
    public partial class SupportRequestSA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //I tried this with both lines below, I could not get either to work. The Sys Admins created a user named "MyDomain\adquery" for me
			DirectoryEntry group = new DirectoryEntry("LDAP://CN=CSR Admins,OU=ServiceAccounts,DC=MyDomain,DC=COM");
            //DirectoryEntry group = new DirectoryEntry("LDAP://CN=CSR Admins,OU=ServiceAccounts,DC=MyDomain,DC=COM", "MyDomain\adquery", "password123456");
            ArrayList ArrUsers = new ArrayList();
            object members = group.Invoke("Members", null);
            foreach (object member in (IEnumerable)members)
            {
                DirectoryEntry x = new DirectoryEntry(member);
                //Console.WriteLine(x.Name);
                ArrUsers.Add(x.Name.Substring(3));
                //ArrUsers.Add(x.Name.Replace("CN=", "")) ;
                //(Replace("CN=", "")
                //ArrUsers.Add(x.Name.Replace("CN=", ""));
            }
            DropDownList3.DataSource = ArrUsers;
            DropDownList3.DataBind();
        }


    }
}

Open in new window


My goal is have the web page build a drop down list from all the users in an AD group....please help....
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

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
Avatar of sqlagent007

ASKER

The web server is in house, and the security team does not want the web server to be on the domain.
So how will your site know about your AD domain when the server doesn't?

/gustav
I got them to put the server on the domain...all is good now.
Fine! They probably realised that it doesn't hurt.

/gustav