1
votes

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?

2

2 Answers

0
votes

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?

0
votes

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.