Get names of all roles using GetRoleNameList()

  • 23 May 2012
  • 1 reply
  • 0 views

Badge +6

I followed the concept in this link:


http://www.k2underground.com/blogs/chrisg/archive/2008/04/29/getting-at-roles-via-the-api.aspx


to try to get all the roles using GetRoleNameList(). However I get an error "Login failed for user 'NT Authorityanonymous logon'. I am debugging this from my dev PC. What i dont understand is that i use the same connection and can get the role, add/remove from the role without any issues. The first part works fine. The section is green is where it fails. See my code below:

UserRoleManager
urmServer = new UserRoleManager();
Role _role;
urmServer.CreateConnection();
SCConnectionStringBuilder builder = new SCConnectionStringBuilder()
{Host =
"myservername",
Port = 5555,
Integrated =
true,
IsPrimaryLogin =
true,
Authenticate =
true,
};
urmServer.Connection.Open(builder.ConnectionString);
_role = urmServer.GetRole("myrolename");

string
test = string.Empty;
foreach (RoleItem roleitem in _role.Include)
{
test = roleitem.Name;
}
_role.Include.Add(new UserItem("K2:username"));
urmServer.UpdateRole(_role);



this part fails with NT AUthorityAnonymous logon failure:
string[] myroles = urmServer.GetRoleNameList();



 



 



 



 



 



 



 



 



 



 



 



 



 



urmServer.Connection.Close();


My goal is to get a list of all the roles. Perhaps there is another way?



thanks



 



 



 



 



 



 



 



 





1 reply

Badge +6

You can use out of box K2 service type “User Role Manager Service” ( you can create smart object , if does not exists).


Role.GetRoles Method returns list of roles in your workspace.


 


Note: you can verify using K2 SMO tester , I am using K2 KB 1370


 


Let me know if you need more details

Reply