0

PrincipalConext is giving this error. :

PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);
public bool GetUserGroupInfo(string userName, string PrincipalSamAccountName) {

 bool UserAvailableFlg = false; try { string[] vs = userName.Split('@');

PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);
            UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, userName);
            UserDisplayName = user.DisplayName;
            if (user != null)
            {
                var grp = user.GetAuthorizationGroups().Where(n =\> n.SamAccountName.Equals(PrincipalSamAccountName)).FirstOrDefault();
                if (grp != null)
                {
                    PrincipalCollection principals = ((GroupPrincipal)grp).Members;



                    var users = (from n in principals
                                 where n.SamAccountName.Equals(vs\[0\])
                                 select new
                                 {
                                    n.Name,
                                    n.SamAccountName
                                 }).ToList();
                    if (users != null)
                    {
                        UserAvailableFlg = true;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            return false;
        }
        return UserAvailableFlg;
    }
Subhankar
  • 1
  • 1
  • That is not something we can fix. Is your domain server configured to accept ldap requests? Are you domain joined? Are the DNS records correctly setup? Ask your admin or if you are the admin, verify your settings on the domain controller. – rene Apr 08 '23 at 09:47
  • Can you please explain where can i check the domain controller to verify above points – Subhankar Apr 10 '23 at 09:17

0 Answers0