Reputation: 10015
Assume that we have this context
private static readonly PrincipalContext Context =
new PrincipalContext(ContextType.Domain, "255.255.255.252",
"OU=TestOrgUnit,DC=as,DC=asf",
"blabla", "12345");
I'm searching for users in this domain. I get their's names as SomeNickName
, but they should be DomainName\SomeNickName
.
Is it possible to get a DomainName
from PrincipalContext
object? I found a solution for DirectoryEntry
, but cannot convert PrincipalContext
into it.
This code
DirectoryEntry deBase = new DirectoryEntry("255.255.255.252", "AdminLogin", "PWD");
and this code
DirectoryEntry deBase = new DirectoryEntry("255.255.255.252://OU=TestOrgUnit,DC=as,DC=asf", "AdminLogin", "PWD");
throws an exception and doesn't work.
Upvotes: 1
Views: 1620
Reputation: 697
So technically you have the domain info in the DN you've specified for the connecting OU (DC=as,DC=asf). The first DC is the pre-Win2K name which seems to be what you're looking for.
As far as the PrincipalContext itself containing the domain info it seems that it doesn't.
If you want to use the DE to get more properties or to do your user search, you need to create it like this:
var deBase = new DirectoryEntry("LDAP://255.255.255.252/OU=TestOrgUnit,DC=as,DC=asf", "AdminLogin", "PWD")
Upvotes: 1