public string[] GetUpnSuffix()
{
DirectoryEntry RootDSE = new DirectoryEntry("LDAP://RootDSE");
if (RootDSE != null)
{
// Legge il context name
string strNamingContext = RootDSE.Properties["defaultNamingContext"].Value.ToString();
string strConfigContext = RootDSE.Properties["configurationNamingContext"].Value.ToString();
// Legge il domain name
DirectoryEntry oDomain = new DirectoryEntry("LDAP://" + strNamingContext);
string strDomainName = oDomain.Properties["name"].Value.ToString();
DirectoryEntry oPartition = new DirectoryEntry("LDAP://CN=Partitions," + strConfigContext);
string[] res = new string[oPartition.Properties["UPNSuffixes"].Count + 1];
// Legge il DNS name del dominio
oDomain.RefreshCache(new string[] { "canonicalName" });
if (oDomain.Properties["canonicalName"].Count > 0)
res[0] = oDomain.Properties["canonicalName"][0].ToString().Substring(0, oDomain.Properties["canonicalName"][0].ToString().Length - 1);
else
throw new ApplicationException("Impossibile leggere il canonicalName");
// Legge gli UPN Suffix name del dominio
int idx = 1;
foreach (string suffix in oPartition.Properties["UPNSuffixes"])
{
res[idx] = suffix;
idx++;
}
return res;
}
else
return null;
}
|