Add User To Role using API

  • 27 August 2010
  • 2 replies
  • 1 view

Badge +8

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.


2 replies

Badge +5

        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)
        {


        }

Badge +11

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

Reply