Populating fields from Active Directory in asp.net -- Urgent!

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I have an asp.net application that needs to fill a series of checkboxes with
usernames from a particular group in Active Directory.

Could someone please point me in the right direction in regards to a snippet
of code or a link to where I might info on this? I've checked msdn and can
find nothing definate.

Thanks in advance,

Jay
 
Start with System.DirectoryServices.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
This is basic code that will list out all the user name. I would advise to
also look into the Filter property of the DirectorySearcher
Of course you would have to change the Response.Write's to whatever or
however you want to output the data retreived
I hope this helps!

DirectoryEntry de = new
DirectoryEntry(ActiveDirectoryQuery,Username,Password);
DirectorySearcher ds = new DirectorySearcher(de);
try{
SearchResultCollection src = ds.FindAll();
foreach(SearchResult sr in src){
Response.Write(sr.Properties["samaccountname"][0].ToString();
}
}
catch(Exception ex){
Response.Write(ex.Message);
}
 
Thanks very much the snippet, I can now search my AD structure and filter,
etc without a problem but I've run into one more snag:

Must I use a specific username and password to access my AD or can I somehow
use the already authenticated user credentials? Obviously I can populate
the Username using iPrincipal but how can I tell it to use its associated
password??

Thanks again in advance,

Jay


A. Elamiri said:
This is basic code that will list out all the user name. I would advise to
also look into the Filter property of the DirectorySearcher
Of course you would have to change the Response.Write's to whatever or
however you want to output the data retreived
I hope this helps!

DirectoryEntry de = new
DirectoryEntry(ActiveDirectoryQuery,Username,Password);
DirectorySearcher ds = new DirectorySearcher(de);
try{
SearchResultCollection src = ds.FindAll();
foreach(SearchResult sr in src){
Response.Write(sr.Properties["samaccountname"][0].ToString();
}
}
catch(Exception ex){
Response.Write(ex.Message);
}

--
Abdellah Elamiri
.net Developer
Efficacy through simplicity


Jay said:
I have an asp.net application that needs to fill a series of checkboxes with
usernames from a particular group in Active Directory.

Could someone please point me in the right direction in regards to a snippet
of code or a link to where I might info on this? I've checked msdn and can
find nothing definate.

Thanks in advance,

Jay
 
Back
Top