Guest User

Untitled

a guest
Jul 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public static MembershipUserCollection FindUsersByRole(string[] roles)
  2. {
  3. MembershipUserCollection msc = new MembershipUserCollection();
  4.  
  5. roles.Select(role => Roles.GetUsersInRole(role))
  6. .Aggregate((a, b) => a.Union(b).ToArray())
  7. .Distinct()
  8. .Select( user => Membership.GetUser(user))
  9. .ToList().ForEach( user => msc.Add(user));
  10.  
  11. return msc;
  12. }
  13.  
  14. public static List<MembershipUser> FindUsersByRole(string[] roles)
  15. {
  16. var userList = roles.Select(role => Roles.GetUsersInRole(role))
  17. .Aggregate((a, b) => a.Union(b).ToArray())
  18. .Distinct()
  19. .Select( user => Membership.GetUser(user))
  20. .ToList();
  21. return userList;
  22. }
  23.  
  24. public static List<string> FindUsersByRole(string[] roles)
  25. {
  26. var userList = roles.Select(role => Roles.GetUsersInRole(role))
  27. .Aggregate((a, b) => a.Union(b).ToArray())
  28. .Distinct()
  29. .ToList();
  30. return userList;
  31. }
  32.  
  33. List<string> roleset_to_find = new List<string>() {"RoleA","RoleB"};
  34.  
  35. List<string> membersFound = new List<string>();
  36.  
  37. foreach (string role in roleset_to_find)
  38. {
  39. membersFound.AddRange(Roles.GetUsersInRole(role));
  40. }
  41.  
  42. string[] roles = {"role1", "role2" };
  43. string[] tempusers = new string[]{};
  44. List<string> users = new List<string>();
  45. foreach (string role in roles)
  46. {
  47. string[] usersInRole = Roles.GetUsersInRole(role);
  48. users = tempusers.Union(usersInRole).ToList();
  49. tempusers = users.ToArray();
  50. }
  51. foreach (string user in users) { Response.Write(user + "<br/>"); }
Add Comment
Please, Sign In to add comment