2009-05-22 9 views
0

Je reçois la propriété memberOf pour mon utilisateur en utilisant ce code:nom du groupe AD avec caractère «/» souffle mon contraignant

DirectorySearcher search = new DirectorySearcher(new DirectoryEntry(connectionString)); 
search.Filter=string.Format("(&(sAMAccountName={0})(objectClass=user))",userName); 
SearchResult result = search.FirndOne(); 

Jusqu'à présent, si bon. Cependant, je dois alors obtenir la valeur cn pour chaque groupe dont l'utilisateur est membre: je le fais en boucle sur la propriété memberOf.

List<string> groupList = new List<string>(); 
DirectoryEntry user = result.GetDirectoryEntry(); 

foreach(string groupPath in user.Properties["memberOf"]) 
{ 
    DirectoryEntry groupBinding = new DirectoryEntry("LDAP://"+groupPath); 
    DirectorySearcher groupSearch = new DirectorySearcher(groupBinding); 
    DirectoryEntry gorupEntry = groupSearch.FindOne().GetDirectoryEntry(); 
    groupList.Add(groupEntry.Properties["cn"].Value.ToString())); 
} 

Le problème est que lorsque le groupPath inclut un caractère «/» le groupSearch.FindOne() lève une exception. Comment puis-je échapper le caractère/afin que je puisse rechercher ce groupe?

Répondre

Questions connexes