Get list of users with specific Membership Type

Tony Feltham asked on March 22, 2018 10:15

Very basic question .....

How do you get a list of users who have a certain Membership type ?

I could write a custom query but I assume there must be an API call to do this but I cant find it

Correct Answer

Dragoljub Ilic answered on March 22, 2018 11:25

Hi Tony,

You can use something like this: UserInfoProvider.GetUsers().Where(user => user.IsInMembership("MembershipName", SiteContext.CurrentSiteName)).ToArray();

If your base of users is really big, then I will go with some custom query, by combining CMS_Membership and CMS_MemberhsipUser tables to get all UserID's of given membership.

You can also retrieve first Membership id based on name, and then use MembershipUserInfoProvider like this:

var membership = MembershipInfoProvider.GetMembershipInfo("MembershipName", SiteContext.CurrentSiteName);
MembershipUserInfoProvider.GetMembershipUsers().WhereEquals(nameof(MembershipUserInfo.MembershipID), membership.MembershipID);

Best regards, Dragoljub

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.