I am trying to figure out the best way of getting domain name and the rest of the information into 2 strings by using regex or maybe an exsiting String method available from LDAP string.
Here is the active directory connection string:
"LDAP://yourdomain.com/OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com"
and the out put I would like to get is:
string DomainName = "yourdomain.com"
string Container = "OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com"
It's a standard URL (with protocol LDAP) and I would use the appropriate URL parsing/objects available to you.
var uri = new Uri(LDAPConnectionString);
var host = uri.Host;
var Container = uri.Segments[1];
etc.
This can be done using simple string manipulation (no need for a Regex).
var parts = "LDAP://yourdomain.com/OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com".Replace("LDAP://", "").Split('/');
Console.WriteLine(parts[0]); // yourdomain.com
Console.WriteLine(parts[1]); // OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.