Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert domain name to LDAP-style in .NET

Is there a built-in C# function to convert a dot-style domain name (my.domain.name) to LDAP style domain components (dc=my,dc=domain,dc=component?

like image 450
Joe Zack Avatar asked Jan 21 '23 19:01

Joe Zack


1 Answers

string GetDomainDN(string domain)
{
    DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domain);
    Domain d = Domain.GetDomain(context);
    DirectoryEntry de = d.GetDirectoryEntry();
    return de.Properties["DistinguishedName"].Value.ToString();
}
like image 90
Harvey Kwok Avatar answered Jan 31 '23 04:01

Harvey Kwok