Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sebastian Dammark 583 posts 1407 karma points
    Feb 18, 2020 @ 14:00
    Sebastian Dammark
    0

    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 ?

  • John C Scott 473 posts 1183 karma points
    Feb 18, 2020 @ 14:19
    John C Scott
    0

    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.

  • Sebastian Dammark 583 posts 1407 karma points
    Feb 19, 2020 @ 08:56
    Sebastian Dammark
    0

    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.

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    Feb 19, 2020 @ 09:11
    Anders Bjerner
    1

    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 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.

  • Sebastian Dammark 583 posts 1407 karma points
    Feb 19, 2020 @ 09:45
    Sebastian Dammark
    0

    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.

  • Halden Collier 4 posts 84 karma points
    Feb 02, 2021 @ 11:19
    Halden Collier
    0

    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)

Please Sign in or register to post replies

Write your reply to:

Draft