By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,216 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,216 IT Pros & Developers. It's quick & easy.

Roles and Memberships

P: n/a
Ron
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
May 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" wrote:
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

May 16 '06 #2

P: n/a
Ron
Thank you for the response i will give this a try.

Ron

"Peter Bromberg [C# MVP]" wrote:
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" wrote:
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

May 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.