0

Im trying to figure out using .NET CSOM if a specific user is a member of a SP group through an AD group. Currently we have the following code running, but if a user is added to an SP group using an AD group he/she slips through the cracks.

 public bool UserIsMemberOfGroup(string loginName, string groupName)
        {
                var siteContext = _applicationContext.CurrentSiteContext.ElevatedClientContext;

                var siteGroup = siteContext.Web.SiteGroups.GetByName(groupName);
                siteContext.Load(siteGroup, group => group.Users);
                siteContext.ExecuteQueryRetry();

                var loginNameLowerCase = loginName.ToLower();

                var userInGroup = siteGroup.Users.FirstOrDefault(user => user.LoginName.ToLower().EndsWith(loginNameLowerCase));

                return userInGroup != null;
        }

I suppose I could check all AD groups within a SP group to see if the user is a member of any of those. But I recon there should be an easier way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.