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 conntections. 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
ASKED:
June 22, 2012 7:00 PM