Hello folks,
I've been trying to find out for a while,
why I am not getting the user name, when I access the active directory under .NET.
I am using this simple code:
This code yields:
And yes, that's the question. Why am I not getting any user names? Why is
always
?
How do I get them? I need both the SID and the user name for my app...
Thanks for your help,
Steven
I've been trying to find out for a while,
why I am not getting the user name, when I access the active directory under .NET.
I am using this simple code:
Code:
DirectoryEntry entry = new DirectoryEntry("LDAP://OU=User organisation, ...");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
SearchResultCollection result = mySearcher.FindAll();
foreach (SearchResult s in result)
{
DirectoryEntry de = s.GetDirectoryEntry();
Console.WriteLine("Name:\t" + de.Name);
[COLOR=red]Console.WriteLine("Username:\t" + de.Username);[/color]
PropertyCollection p = de.Properties;
if (p["objectSid"].Value == null)
Console.WriteLine("No SID available");
else
Console.WriteLine("SID:\t" +
new SecurityIdentifier((byte []) p["objectSid"].Value, 0).ToString());
[COLOR=red]if (p["username"].Value == null)
Console.WriteLine("No username available");[/color]
else
Console.WriteLine("Username:\t" + (string) p["username"].Value);
Console.WriteLine("################################################\n");
}
Console.WriteLine("Why am I not getting any user names?");
This code yields:
Code:
Name: OU=User organisation
[COLOR=red]Username:[/color] [b]//that should be normal[/b]
No SID available [b]//that should be normal[/b]
No username available [b]//that should be normal[/b]
################################################
Name: CN=Steven
[COLOR=red]Username:[/color] [b]//why is my user name not shown?[/b]
SID: S-1-5-21-3592736010-1634432720-1998580803-xxxxx
No username available [b]//so the value is null! Why?[/b]
################################################
Name: CN=Fantasy U. Ser
[COLOR=red]Username:[/color] [b]//why is 'fantasiy's user name not shown?[/b]
SID: S-1-5-21-3592736010-1634432720-1998580803-yyyyy
No username available [b]//so the value is null! Why?[/b]
################################################
Name: CN=Another User
Username:
SID: S-1-5-21-3592736010-1634432720-1998580803-zzzzz
No username available
################################################
Why am I not getting any user names?
And yes, that's the question. Why am I not getting any user names? Why is
Code:
de.Username
Code:
null
How do I get them? I need both the SID and the user name for my app...
Thanks for your help,
Steven