Active Directory returns No Data

5 pts.
Tags:
RSS feed
Hello; I am a junior developer and I'm building a application that should search and return ALL user name & groups in the Active Directory, my code builds fine and I able to log into the server but I retireve NO data. I believe I have all three part needed for a LDAP search and connections. was wondering if you could take a look at my code and tell me what am I doing wrong.

using

 

 

System;

using

 

 

System.Security;

using

 

 

System.Collections;

using

 

 

System.Configuration;

using

 

 

System.Linq;

using

 

 

System.Web;

using

 

 

System.Web.UI;

using

 

 

System.Web.UI.WebControls;

using

 

 

System.Security.Principal;

using

 

 

System.DirectoryServices;  



namespace

 

 

AuctionDash {

 

 



public partial class ActiveDirectory : System.Web.UI.Page

{

 

 

protected void Page_Load(object sender, EventArgs e) {

 

 



SortedList groupMemebers = new SortedList();  

 



string domainAndUsername = "";  

 



string password = "";  

 



string sam = "";  

 



string fname = "";  

 



string lname = "";  

 



string active = "";  

 



string adPath = "LDAP://" + ConfigurationManager.AppSettings["DefaultActiveDirectoryServer">.ToString();  

 



DirectoryEntry de = new DirectoryEntry(adPath, domainAndUsername, password);

 

 

DirectorySearcher ds = new DirectorySearcher(de, "(&(objectCategory=group)"); ds.SearchScope =

 



SearchScope.Subtree; ds.Filter =

 



"(adfind -default" + "dc=zachys.local" + ",DC=com)"; ds.PropertiesToLoad.Add(

 



"givenname"); ds.PropertiesToLoad.Add(

 



"samaccountname"); ds.PropertiesToLoad.Add(

 



"sn");  

 

 

 



foreach (SearchResult sr in ds.FindAll()) {

 

 



try

{

sam = sr.Properties[

 

"samaccountname">[0].ToString(); fname = sr.Properties[

 



"givenname">[0].ToString(); lname = sr.Properties[

 



"sn">[0].ToString(); active = sr.Properties[

 



"useraccountcontrol">[0].ToString(); }

 

 



catch (Exception) {

}

 

 



// don't grab disabled users

 

 

if (active.ToString() != "514") {

groupMemebers.Add(sam.ToString(), (fname.ToString() +

 



" " + lname.ToString()));  

}

 

}

lblStatus.Text = groupMemebers.ToString();

 

}

}

}



Software/Hardware used:
Visual Studio 2010 and SQL Server 2008

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following