Solved

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

Posted on 2011-09-23
5
136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 50

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 50

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 50

Expert Comment

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

/gustav
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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