Solved

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

Posted on 2011-09-23
5
134 Views
Last Modified: 2012-05-12
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....
0
Comment
Question by:sqlagent007
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 36594837
First, check that the web server knows where to find a local Domain Controller.

Second, if the web server is in-house, why not enter the web server in AD?
If the web server is not in-house it is likely not able to see your local Domain Controllers.

/gustav
0
 
LVL 1

Author Comment

by:sqlagent007
ID: 36595234
The web server is in house, and the security team does not want the web server to be on the domain.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 36595506
So how will your site know about your AD domain when the server doesn't?

/gustav
0
 
LVL 1

Author Closing Comment

by:sqlagent007
ID: 36597072
I got them to put the server on the domain...all is good now.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 36597316
Fine! They probably realised that it doesn't hurt.

/gustav
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question