Solved

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

Posted on 2011-09-23
5
133 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now