Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autherisation in Share point 2007

Status
Not open for further replies.

pkker

Programmer
Sep 25, 2009
3
US
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top