문제

Using System.DirectoryServices (i.e. the DirectoryEntry class) is there a way to convert the DistinguishedName attribute to, or get the Canonical Name that would normally appear in the Active Directory Users & Computers snap-in? I realize I could do this using regular expressions, but I would prefer a more reliable approach.

For example, I want to convert this

CN=Murdock\, James,OU=Disabled Users,OU=GOG,DC=contoso,DC=local

to this

contoso.local/GOG/Disabled Users/Murdock, James

도움이 되었습니까?

해결책

It's a constructed attribute. On a DirectoryEntry, you need to use RefreshCache:

var de = new DirectoryEntry("CN=Murdock\, James,OU=Disabled Users,OU=GOG,DC=contoso,DC=local");
de.RefreshCache(new string[] {"canonicalName"});

다른 팁

You'll want the canonicalName attribute. Assuming you already have the code for getting the user as a DirectoryEntry.

userDe.Properties["canonicalName"][0].ToString()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top