HOW TO: Add users to SharePoint Groups using SharePoint 2013 UserGroup.asmx Web Service
Published May 01 2019 03:49 PM 761 Views
Microsoft

First published on TECHNET on Aug 28, 2013

This post is a contribution from Raghavendra B Nanjaiah, an engineer with the SharePoint Developer Support team.

Problem

When you try to add users through the UserGroup.asmx web service (http://localhost/_vti_bin/UserGroup.asmx) in SharePoint 2013 with the sample code below.

sp.UserGroup usrgrpService = new sp.UserGroup();


usrgrpService.Credentials = new System.Net.NetworkCredential("Administrator", "access", "contoso");





usrgrpService.AddUserToGroup("Dev Members", "usera",


"contoso\\usera", "usera@contoso.com", "Notes");



You will successfully add user to the SharePoint group, but if you look at the user permission or try accessing site using this user credentials, you’ll get “Site is not shared with you” message.



Solution



You have to pass user in claims encoded format (e.g., i:0#.w|contoso\chris ) in SharePoint 2013.  This is because claims authentication is enabled in the web applications you create by default.



Not that this is something that many don’t know, but we’ve had customers reporting this issue to us and we thought we’ll get this message out!



HTH

Version history
Last update:
‎Sep 01 2020 02:38 PM
Updated by: