private UserPrincipal FindUserUsingFilter(string userName, PrincipalContext context) { CustomUserPrincipal userPrincipal = new CustomUserPrincipal(context); userPrincipal.SetUserNameFilter(userName); PrincipalSearcher searcher = new PrincipalSearcher(userPrincipal); return(searcher.FindOne() as UserPrincipal); }