fter my authentication i was trying to add the user to the sharepoint site groups for the authorization of the user by using the code below
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPWeb web = new SPSite(this.Request.Url.AbsoluteUri.Replace(this.Request.Url.LocalPath, "")).OpenWeb();
web.AllowUnsafeUpdates = true;
//Assign role and add user to site
SPRoleAssignment spRoleAssignment =new SPRoleAssignment(login.UserName, "", login.UserName, "");
//Using Contribute, might need high access
SPRoleDefinition spSPRoleDefinition =web.RoleDefinitions["Contribute"]
spRoleAssignment.RoleDefinitionBindings.Add(spSPRoleDefinition);
web.RoleAssignments.Add(spRoleAssignment);
//Update site
web.Update();
Microsoft.SharePoint.Administration.SPWebApplication webApp = web.Site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
SPGroup spGroup = web.SiteGroups["Authentication test Members"];
spGroup.OnlyAllowMembersViewMembership = false;
//Add and update group with new user
spGroup.AddUser(login.UserName, "", login.UserName, "");
spGroup.Update();
webApp.FormDigestSettings.Enabled = true;
if (web != null)
{
web.Dispose();
}
//web.AllowUnsafeUpdates = true;
//// add user to group and update it
//associatedMemberGroup.AddUser(defaultProvider + ":" + sUserName, sEmail, sUserName, "");
//associatedMemberGroup.Update();
//web.AllowUnsafeUpdates = false
//web.Dispose();
});
Error:The user does not exist or is not unique
Could you provide me the solution for adding users to the site groups for Authorization.
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPWeb web = new SPSite(this.Request.Url.AbsoluteUri.Replace(this.Request.Url.LocalPath, "")).OpenWeb();
web.AllowUnsafeUpdates = true;
//Assign role and add user to site
SPRoleAssignment spRoleAssignment =new SPRoleAssignment(login.UserName, "", login.UserName, "");
//Using Contribute, might need high access
SPRoleDefinition spSPRoleDefinition =web.RoleDefinitions["Contribute"]
spRoleAssignment.RoleDefinitionBindings.Add(spSPRoleDefinition);
web.RoleAssignments.Add(spRoleAssignment);
//Update site
web.Update();
Microsoft.SharePoint.Administration.SPWebApplication webApp = web.Site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
SPGroup spGroup = web.SiteGroups["Authentication test Members"];
spGroup.OnlyAllowMembersViewMembership = false;
//Add and update group with new user
spGroup.AddUser(login.UserName, "", login.UserName, "");
spGroup.Update();
webApp.FormDigestSettings.Enabled = true;
if (web != null)
{
web.Dispose();
}
//web.AllowUnsafeUpdates = true;
//// add user to group and update it
//associatedMemberGroup.AddUser(defaultProvider + ":" + sUserName, sEmail, sUserName, "");
//associatedMemberGroup.Update();
//web.AllowUnsafeUpdates = false
//web.Dispose();
});
Error:The user does not exist or is not unique
Could you provide me the solution for adding users to the site groups for Authorization.