Solved

How can i call Membership.GetAllUsers but only get users within a specified role

Posted on 2010-08-16
2
637 Views
Last Modified: 2012-05-10
How can i call Membership.GetAllUsers but only get users within a specified role.

I'm aware of Roles.GetUsersInRole("Comgem") however this doesnt return the membersip columns i'm looking for.

Is this possible, while maintaining the same results set returned by GetAllusers?

Thanks
0
Comment
Question by:Webbo_1980
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 23

Expert Comment

by:Snarf0001
ID: 33450164
No single step way to do it:
The MembershipUser itself has no knowledge of what roles a user belongs to, that has to be queried from the RoleProvider as you've shown.

But, if you can use linq, a pretty easy to query the objects to get what you're after:
var members = from m in Membership.GetAllUsers().OfType<MembershipUser>()
                join u in Roles.GetUsersInRole("Comgem") on m.UserName equals u
                select m;

Open in new window

0
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 33450195
Note though, that depending on what provider you're using, and how many users you have vs how many are in the target role, there's a really good chance you'd get better performance by calling GetUsersInRole by itself, and then for each one returning the Membership.GetUser("").

var members = Roles.GetUsersInRole("Comgem").Select(u => Membership.GetUser(u));
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question