Skip to main content

I am attempting to add/delete users to a role using the SourceCode.Security.UserRoleManager.Management API.  Does anyone have a code snippet on how to do this. I am creating the Role object but the only add method I see is LoadData and that apears to be for the entire role and not just one member.

        SCConnectionStringBuilder connString = new SCConnectionStringBuilder();
        connString.Authenticate = true;
        connString.Host = "K2ServerName";
        connString.Integrated = true;
        connString.IsPrimaryLogin = true;
        connString.Port = 5555;


        try
        {
            Role role = new Role();
            UserRoleManager roleManager = new UserRoleManager();


            roleManager.CreateConnection();
            roleManager.Connection.Open(connString.ToString());


            role = roleManager.GetRole("Name of Role to Add User to");
            role.Include.Add(new UserItem("MyDomainUserLogin"));


            roleManager.UpdateRole(role);
            roleManager.Connection.Close();
           
        }
        catch(Exception ex)
        {


        }


you can add users to the destination rule code without invoking any roles


see code in the following link


http://www.k2underground.com/forums/t/13046.aspx


It appears that the API for K2 5.7 no longer supports Role.Include

 

Is there an updated API available?

 


It looks like I figured it out.

Rather than  role.Include.Add(new UserItem("UserID"));

use role.RoleItems.Add(new UserItem(“UserID”));

 


Reply