Solved

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

Posted on 2010-08-16
2
622 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
  • 2
2 Comments
 
LVL 22

Expert Comment

by:Snarf0001
Comment Utility
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 22

Accepted Solution

by:
Snarf0001 earned 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now