Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying this code:

public bool isTravelAdmin(string srvr, string usr, string password)
{
    System.Diagnostics.Debug.WriteLine("I'm in isTravelAdmin!");

    PrincipalContext domainctx = new PrincipalContext(ContextType.Domain, srvr);

    UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(domainctx, IdentityType.SamAccountName, usr);

    bool isMember = userPrincipal.IsMemberOf(domainctx, IdentityType.Name, "traveladmin");

    if (isMember)
    {
        System.Diagnostics.Debug.WriteLine("This user is INDEED a member of that group");
        return true;
    }
    else
    {
        System.Diagnostics.Debug.WriteLine("This user is *NOT* member of that group");
        return false;
    }
}


Which is supposed to check if a user belongs to a certain group ("traveladmin"), but I'm getting

System.DirectoryServices.AccountManagement.PrincipalServerDownException

Any idea why and how to solve? by the way:
srvr = "LDAP://192.168.56.101/CN=Users,DC=estagioit,DC=local"

PS: I'm using the same srvr on another method and it's working and connecting.

PSS: If this is not the best way to go about this I'm open to suggestions.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900