lundi 21 août 2017

how we can Get specfic User from Active Directory after creating new user in c#

i am creating new user in Active Directory but after creating it when i am retrieving created user the fo llowing error is coming " An operations error occurred "

following is my code

private static DirectoryEntry GetUser(string userName)
    {
        var de = Utility.GetDirectoryObject();
        var deSearch = new DirectorySearcher
        {
            SearchRoot = de,
            Filter = "(&(objectClass=user)(sAMAccountName=" + userName + "))",
            SearchScope = SearchScope.Subtree
        };
        var results = deSearch.FindOne();
        if (results != null)
        {
            de = new DirectoryEntry(results.Path, Utility.AdUser, Utility.AdPassword, AuthenticationTypes.Secure);
            return de;
        }
        return null;
    }




Aucun commentaire:

Enregistrer un commentaire