Roles and Memberships

G

Guest

Hi,
I need to retrieve only users and there information in the aspnet_Membership
table that are associated with certain roles and then populate a GridView
with only those users found that belong to those roles.
I have searched through all the class associated to try and find some method
that would help but i think i am missing something.
Any suggestions would be greatly appreciated.

Thanks Ron
 
G

Guest

Ron,
this should point you in the right direction. You can thank Peter Kellner
(not me) for the sample code:

static public List<RoleData> GetRoles(string userName, bool
showOnlyAssignedRolls)
{
List<RoleData> roleList = new List<RoleData>();
string[] roleListStr = Roles.GetAllRoles();
foreach (string roleName in roleListStr)
{
bool userInRole = false;
// First, figure out if user is in role (if there is a user)
if (userName != null)
{
userInRole = Roles.IsUserInRole(userName, roleName);
}

if (showOnlyAssignedRolls == false || userInRole == true)
{
// Getting usersInRole is only used for the count below
string[] usersInRole = Roles.GetUsersInRole(roleName);
RoleData rd = new RoleData();
rd.RoleName = roleName;
rd.UserName = userName;
rd.UserInRole = userInRole;
rd.NumberOfUsersInRole = usersInRole.Length;
roleList.Add(rd);
}
}
return roleList;
}
 
G

Guest

Thank you for the response i will give this a try.

Ron

Peter Bromberg said:
Ron,
this should point you in the right direction. You can thank Peter Kellner
(not me) for the sample code:

static public List<RoleData> GetRoles(string userName, bool
showOnlyAssignedRolls)
{
List<RoleData> roleList = new List<RoleData>();
string[] roleListStr = Roles.GetAllRoles();
foreach (string roleName in roleListStr)
{
bool userInRole = false;
// First, figure out if user is in role (if there is a user)
if (userName != null)
{
userInRole = Roles.IsUserInRole(userName, roleName);
}

if (showOnlyAssignedRolls == false || userInRole == true)
{
// Getting usersInRole is only used for the count below
string[] usersInRole = Roles.GetUsersInRole(roleName);
RoleData rd = new RoleData();
rd.RoleName = roleName;
rd.UserName = userName;
rd.UserInRole = userInRole;
rd.NumberOfUsersInRole = usersInRole.Length;
roleList.Add(rd);
}
}
return roleList;
}
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Ron said:
Hi,
I need to retrieve only users and there information in the aspnet_Membership
table that are associated with certain roles and then populate a GridView
with only those users found that belong to those roles.
I have searched through all the class associated to try and find some method
that would help but i think i am missing something.
Any suggestions would be greatly appreciated.

Thanks Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top