Copied to clipboard

Flag this post as spam?

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


  • Damion 96 posts 331 karma points
    Mar 22, 2019 @ 15:34
    Damion
    0

    Umbraco 8 - restrict items on the product page to certain menber groups

    Taking the Umbraco 8 starter site as an example, within the products page, is it possible to restrict different products to different member groups?

    Eg, show all 8 products, but if the user is not a member of a premium group they can only access certain ones?

    If I click on a product in back office, under actions I can see I can amend the public access there, but that then prevented the entire page from being viewed.

    thanks

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Mar 23, 2019 @ 15:23
    Marc Goodson
    0

    Hi Damion

    You could use the IsUserInRole method to detect whether the currently logged in Member is in a particular member group, to show or hide particular content:

    @if (Roles.IsUserInRole("SuperSecretMemberGroup"))
    {
        <p>Super secrets here!</p>
    }
    

    or you could add a 'Member Group Picker' to the Product Type to pick which Member Groups should have access to the particular product, and then get a list of the Current Users Member groups using:

    @{ 
        var currentUsersRoles = Roles.GetRolesForUser();
    }
    

    and then use this to filter the products so you only show ones with MemberGroups that match the current users...

    regards

    marc

  • Damion 96 posts 331 karma points
    Mar 25, 2019 @ 09:01
    Damion
    0

    Hi

    thanks for the reply. I like the look of IsUserInRoll, I'll try it shortly, this would go in as a macro then?

    thanks

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Mar 25, 2019 @ 14:17
    Marc Goodson
    100

    Hi Damion

    Yes in a Template/View, Partial View or Macro Partial.

    Should be the same.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft