The helper do have methods for that, but unfortunately only in Umbraco 8.
In Umbraco 7, this part is instead delegated to ASP.NET, which has the System.Web.Security.Roles class. So you can call Roles.GetRolesForUser(username) and get an array back with the names of the member groups the member is a part of.
Be aware that looking up the roles for many users at once may be expensive. I think the helper in Umbraco 8 also relies on the Roles class internally, but adds some caching on top of it.
Of course it's on Umbraco 7 :)
I'll only be looking up on a single user, when he logs in and the redirect based on the groups. So I don't think it'll be that expensive.
For those that are looking for the v8 solution, as Anders said, you can now find it in the MembershipHelper:
Members.GetUserRoles(userName: objMember.Username)
How to get the groups of the current logged in member ?
How can I get a list of member groups of the currently logged in member ?
Have you tried the Membership Helper?
https://our.umbraco.com/documentation/Reference/Querying/MemberShipHelper/
Is this via a controller? In C#?
If you do have any further questions please ask.
Hi John,
I've looked at the MemberShipHelper, but can't really see anything regarding Groups or Roles.
It's actually in the Partial View Macro
Login.cshtml
that comes with the Umbraco solution.Hi Sebastian,
The helper do have methods for that, but unfortunately only in Umbraco 8.
In Umbraco 7, this part is instead delegated to ASP.NET, which has the
System.Web.Security.Roles
class. So you can callRoles.GetRolesForUser(username)
and get an array back with the names of the member groups the member is a part of.Be aware that looking up the roles for many users at once may be expensive. I think the helper in Umbraco 8 also relies on the
Roles
class internally, but adds some caching on top of it.Ahhh ... cool.
Of course it's on Umbraco 7 :) I'll only be looking up on a single user, when he logs in and the redirect based on the groups. So I don't think it'll be that expensive.
Thanks.
Umbraco v8
For those that are looking for the v8 solution, as Anders said, you can now find it in the MembershipHelper:
Members.GetUserRoles(userName: objMember.Username)
is working on a reply...