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 543 posts 1261 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 457 posts 1157 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 543 posts 1261 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 444 posts 2574 karma points MVP 4x admin c-trib
    Feb 19, 2020 @ 09:11
    Anders Bjerner
    0

    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 543 posts 1261 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.

Please Sign in or register to post replies

Write your reply to:

Draft