I'm encountering problems adding "some" users(of a certain domain) to a group..
The code works every "domain1" user, but for "domain2" for doesn't:
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite scSite = new SPSite(fullsite))
{
using (SPWeb scWeb = scSite.OpenWeb())
{
scWeb.AllowUnsafeUpdates = true;
scSite.AllowUnsafeUpdates = true;
SPGroup gruppo = scWeb.SiteGroups[groupName]; //FIND
SPUser utente = scWeb.EnsureUser(username); //FIND
gruppo.AddUser(utente);
gruppo.Update();
}
}
});
Exception is:
You do not have permission to perform this action or access this resource. at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.UpdateMembers(String bstrUrl, UInt32 dwObjectType, String bstrObjId, Guid& pguidScopeId, Int32 lGroupID, Int32 lGroupOwnerId, Object& pvarArrayAdd, Object& pvarArrayAddIds, Object& pvarArrayLoginsRemove, Object& pvarArrayIdsRemove, Boolean bRemoveFromCurrentScopeOnly, Boolean bSendEmail)
at Microsoft.SharePoint.SPUserCollection.UpdateMembers(Object objUpdateInfo, Object objAddIds, Object objRemoveLogins, Object objRemoveIds, Boolean fSendEmail)
at Microsoft.SharePoint.SPUserCollection.AddCollection(SPUserInfo[] addUsersInfo, IEnumerable`1 addUsers)
at Microsoft.SharePoint.SPUserCollection.Add(String loginName, String email, String name, String notes)
at Microsoft.SharePoint.SPGroup.AddUser(SPUser user)
If I manually add the users, everything goes fine..
Context info: that code runs on a Web Service. I also tryed to run it as Console App and Web Part.. But with no changes on the behavior.
The problem I'm facing is probably caused by the 2 domain the machine is trusted with: with 1 domain I have no problem, with the other system fails to add users to group by code but with people picker everithing goes fine..
I begin to think I have a problem with privilegs on AD or something like that.. Any suggestion?
Thank you very much!