MSDN Magazine - February 2008 - (Page 55) principals with the control. Then you can supply the code that actually adds these principals as site members and configures their access rights. Now I should show you how to add an external user or group as a site member. After a brief look at the WSS object model, you might think that you should simply add external security principals directly into one of the SPUser collections, such as SiteUsers: SPWeb site = SPContext.Current.Web; site.SiteUsers.Add(@”LITWAREINC\BrianC”, “brianc@litwareinc.com”, “Brian Cox”, “Notes about Brian Cox”); site.SiteUsers.Add(@”LITWAREINC\AllFTE”, “allFTE@litwareinc.com”, “All Full-time Employees”, “Notes about FTE DL”); mission levels: Read, Contribute, Design, and Full Access. If you need greater granularity than this, you can create your own custom permission levels using the WSS object model or through the standard WSS administrative pages that are accessible to the site collection owner. Permission levels are sometimes called roles, and they are represented in the WSS object model using SPRoleDefinition objects. You can assign a permission level to an external user or groups using a SPRoleAssignment object. For example, here I assign the built-in Contribute permission level to the Windows user with a login name of LITWAREINC\BrianC: SPWeb site = SPContext.Current.Web; SPRoleDefinition role = site.RoleDefinitions[“Contribute”]; SPRoleAssignment roleAssignment; roleAssignment = new SPRoleAssignment(@”LITWAREINC\BrianC”, “brianc@litwareinc.com”, “Brian Cox”, “Notes about Brian Cox”); roleAssignment.RoleDefinitionBindings.Add(role); site.RoleAssignments.Add(roleAssignment); While this approach does create a profile in the User Information List for an external principal, it has little effect on security since it doesn’t assign a permission. A better way to add a new external security principal involves assigning permissions so that users have access within the current site. However, you first need to learn how to create and assign permission levels. Working with Permission Levels A permission level is a named set of permissions that is defined within the scope of a site. WSS includes four built-in per- This technique makes it unnecessary to add the user to one of the SPUser collections since that is done automatically by WSS when an external user or group is assigned a permission for the first time within a site. The code you’ve just seen will create a user profile in the User Information List if one does not exist, and it will also add the user as a member of the current site’s Users collection. Office Space february2008 55 http://msdn.primalscript.com http://msdn.primalscript.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.