How to get sitefinity built in roles programmatically
Hey all,
The following code is some test code that I've put into a user control to experiment with.
01.protected void SubmitButton_Click(object sender, EventArgs e)02.03. // Get membership user04. User user = (User)Membership.GetUser(UserNameTextBox.Text, true);05. 06. // Get Sitefinity role manager07. var roleManager = RoleManager.GetManager();08. 09. // Get all roles10. var roles = roleManager.GetRoles().ToList();11. 12. // Get all roles for a particular user13. var rolesForUser = roleManager.GetRolesForUser(user.Id).ToList();14. 15. // Putting this into a string for simple testing and spitting out to an asp:Label16. string strRoles = string.Empty;17. 18. int i = 0;19. foreach (Role role in rolesForUser)20. 21. bool printComma = i != rolesForUser.Count() - 1;22. strRoles += role.ToString();23. strRoles += printComma ? ", " : string.Empty;24. 25. i++;26. 27. 28. string data = string.Format("information [user: 0, creation_date: 1, roles: 2]", user.UserName, user.CreationDate.ToString(), strRoles);29. LabelDisplay.Text = data; 30.Hello Doug,
I think that this is explained in this post.
All the best,
Ivan Dimitrov
the Telerik team
Thanks