DirectoryEntry de = new DirectoryEntry(String.Empty, Username, Password);
if (!String.IsNullOrEmpty(de.Name))
{
using (PrincipalContext domain = new PrincipalContext(ContextType.Domain))
using (UserPrincipal user = UserPrincipal.FindByIdentity(domain, Username))
{
var groups = user.GetGroups();
foreach (Principal p in groups)
{
if (
// If there are no search filters, lets return all
(SearchCriteria.Count == 0) ||
//Check if the group matches(partially and case insensitively to the Search Criteria list)
SearchCriteria.Where(s => !String.IsNullOrEmpty(s) && p.Name.ToLower().Contains(s.ToLower())).Count() > 0
)
{
MatchedGroupsList.Add(p.Name);
}
} // ForEach
} // Using
} //de.Name validation
AD Roles
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.