It sounds quite trivial to me , but going over MemberService API again and again , I still couldn't resolve this simple issue:
How can I get a list of member's roles by this member Id (or user name) ?
For now, I came up only with this solution which is time consuming:
var roles = member_service.GetAllRoles();
foreach (var role in roles)
{
if (member_service.FindMembersInRole(role, member.Username).Contains(member))
{
//add this role to a list of this member roles ...
}
}
I try to run this code on Razor, so I get the current logged in member:
String user_name = Membership.GetUser().UserName;
var member_service = ApplicationContext.Current.Services.MemberService;
var member = member_service.GetByUsername(user_name);
MemberService - get Roles by Member
It sounds quite trivial to me , but going over MemberService API again and again , I still couldn't resolve this simple issue:
How can I get a list of member's roles by this member Id (or user name) ?
For now, I came up only with this solution which is time consuming:
Which is really stupid...
Any better idea ?
I think what you need here is a linq statement. Have a look at the aggregate property on an ienumerable.
Could you please add an example ?
thanks
How are you getting the members? And sure just trying to write one :)
I try to run this code on Razor, so I get the current logged in member:
Ok I see what you are doing. You can do this.
Var rolesList = System.Web.Security.Roles.GetAllRolesForUser("userName")
High Five !
Thanks :D glad it worked
Love a thread like this - it's what makes Umbraco, Umbraco.
Thanks Guys!
/n
is working on a reply...