Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Check if user is part of AD group using System.DirectoryServices.AccountManagement namespace

$
0
0
I am trying to validate a user from SharePoint to see if a user exists within an AD group. SharePoint does not allow you to do this so I am using the:

using

 

System.DirectoryServices.AccountManagement;

to validate user existance within that AD group. I found the following method that allows me to validate but bombing on me:

      public bool IsUserInGroup(string username, string groupname, ContextType type)
        {
            PrincipalContext context = new PrincipalContext(type);

            UserPrincipal user = UserPrincipal.FindByIdentity( context,  IdentityType.Name,  username);
            GroupPrincipal group = GroupPrincipal.FindByIdentity(context, groupname);

            return user.IsMemberOf(group);
        }
When I call my method, i get

An operations error occurred.

I read that it might be an impersination error but I have my web.config set up already with:

<

 

authentication mode="Windows" />

<

 

identity impersonate="true" />

Any suggestions from someone that has worked with that namespace on SharePoint? I just want to plainly check to see if a user is part of a certain group on AD from SharePoint.

 

 

 



Victor Palma

Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>