I need to be able to add and remove users from a role in code. I found how to detect if a user is in a role using this code:
if (CSContext.Current.User.RoleKey.IndexOf("Newsletter") != -1){ // member}else{ // non member}
I need to allow users to opt in or out of the role so as to populate the Newsletter group/role.
I have been looking for quite some time and can't find any samples of this code.
-Patrick
This is what I used, for when a user selects an access level... You could do something along similar lines. I manually created the roles through the Control Panel.
CSContext csContext = CSControlUtility.Instance().GetCurrentCSContext(this.Page);
CommunityServer.Components.Roles.AddUserToRole(csContext.User.Username, this.DirectoryLevelsRadioButtonList.SelectedValue);
In addition to what TechLinks said above, To check if a user is in a role
User user; // populate this userif (user.IsInRole(new string[]{"YOUR ROLE"})){ //Is in Role}else{ //Is not in role}
CS Documentation - now available in downloadable PDF form
My CS Site
Copyright© 2008 Telligent Systems Inc. All rights reserved CommunityServer.com • Telligent.com