1

I am programatically adding a AD user to some SharePoint groups.

spWeb.AllowUnsafeUpdates = true;
SPUser lookupUser = spWeb.EnsureUser(username);
if (lookupUser != null)
{
    spGroup.AddUser(lookupUser);
}
spWeb.AllowUnsafeUpdates = false;

Have tried running this, as (logged in with the administrator account) and tried running with elevated privileges.

The user is added to the groups as required. The problem is, when I use the SharePoint function "Check Permissions" under "Site Permissions" it shows the user as having no permissions.

Everywhere I look in the internet simply shows the use of the AddUser method. Am I missing something?

ekad
  • 14,436
  • 26
  • 44
  • 46
Phil Prett
  • 303
  • 3
  • 8

2 Answers2

0

Your group seems to be missing actual permissions to the site. Did you assign the group at least Read permisssions for the site? If not the Check permissions feature works as expected. See this answer for code sample for assigning the group some permissions.

If the group has permissions assigned maybe the problem lies in a missing call to spGroup.Update() after adding the user to group. Have you tried calling this method?

Community
  • 1
  • 1
tomasdeml
  • 339
  • 2
  • 7
  • The groups have permissions. If I add the users manually to the group using the standard SharePoint function it works. The users get the permissions which the groups have. When I use the above mentioned code, the permissions are not taken. Very strange. – Phil Prett Jul 22 '13 at 12:08
  • @PhilPrett Have you tried calling the `spGroup.Update()` method (see my edited answer)? – tomasdeml Jul 22 '13 at 13:26
0

Check if the WebApplication is using Claims Authentication... if so you probably use the wrong username or there are multiple similar users with different usernames ("i:0#.w|\" and "") -> check /_catalogs/users/simple.aspx. Delete the wrong one from the SiteCollection.

pyranha
  • 184
  • 1
  • 4
  • This was the problem. In the different cases of adding and deleting and with the standard sharepoint admin, it was getting mixed up with users with "i:0#.w|" and without. Thanks @pyranha. – Phil Prett Oct 15 '13 at 15:16