Get the list of Domain users - How?

  • Thread starter Thread starter S. Hussain Akbar
  • Start date Start date
S

S. Hussain Akbar

In my internal-use apps, I need the usernames. In non-Net ASP, I could fetch
them from the Domain users list using:

Set objDomain = GetObject("WinNT://MyDomain,domain")
objDomain.Filter = Array("user")
For Each objUser In objDomain
Response.Write "<TR>" &
"<TD>" & objUser.Name & "</TD>" & _
"<TD>" & objUser.FullName & "</TD>" & _
"<TD>" & objUser.Description & "</TD>" & _
"</TR>"
Next

What's the equivalent in ASPNET?
 
Try this code:
(also set <identity impersonate="true"/> in your web.config)

string Domain_Slash_User = Context.User.Identity.Name;
Domain_Slash_Machine = Domain_Slash_Machine.Replace(@"\",
@"/");
string queryString = @"WinNT://" + Domain_Slash_Machine;

DirectoryEntry obDirEntry = new DirectoryEntry
(queryString);
System.DirectoryServices.PropertyCollection coll =
obDirEntry.Properties;

object obVal = coll["FullName"].Value;
_User = obVal.ToString();

Session.Add("UserFullName", _User);
 
Back
Top