Copied to clipboard

Flag this post as spam?

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


  • Shmuel Kessler 9 posts 32 karma points
    Aug 09, 2012 @ 22:13
    Shmuel Kessler
    2

    Member permissions per content area on page

    Is there a way to set member permissions so that certain content gets displayed to one member group and the same content plus more (a sidebar widget) gets displayed to another member group?

    When members log in, they all see nearly the same content on the member home page. And I have a calendar page that can be seen by only one member group. That's set up. But I'd like for that member group to also see a link to the calendar page when they log in.

    When I restricted the sidebar widget to only that group, it showed up anyway for the other group.

    Is there a non-programmatic way to do this?

  • Shmuel Kessler 9 posts 32 karma points
    Aug 09, 2012 @ 22:27
    Shmuel Kessler
    1

    (Sorry I'm adding a comment and not editing; I'm getting an xslt error message when trying to edit.)

    I guess it comes down to:

    Is there a way to show/hide a link based on membership group?

  • Richard Brookes 34 posts 57 karma points
    Aug 09, 2012 @ 23:30
    Richard Brookes
    1

    Hi Shmuel,

    I don't think you are going to be able to do this without using some kind of code, be it either xslt or razor. Is there a reason you don't want to use code either in a macro or a template to do this? It would be a pretty trivial bit of macro code to achieve the result you want.

    How are you writing the link in the first place? Is this not output by a navigation macro anyway? In which case you could easily add your logic in there. If you post how you are getting your link onto the page I can send you the necessary code

    cheers

  • Shmuel Kessler 9 posts 32 karma points
    Aug 10, 2012 @ 00:28
    Shmuel Kessler
    0

    Thanks Richard! Yes, I meant avoiding recompiling but an xslt solution would be perfect. Currentlythe link is just a static link added to the sidebar. But I do have a navigation macro. How do I post that? I have no attachment icon in the wysiwyg, and of course the xslt couldn't be pasted.

  • Richard Brookes 34 posts 57 karma points
    Aug 10, 2012 @ 01:01
    Richard Brookes
    0

    Hi Shmuel,

    Here is some XSLT code that you should be able to incorperate into your navigation. I have implemented a C# method in there to check if the current user is in a particular role "Allowed" in this case. Then I call this fuction from an if statement and either show a link or not depending on whether the user is in the role or not.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:google.maps="urn:google.maps" xmlns:consea="urn:consea" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets google.maps consea
    ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <msxml:script implements-prefix="consea" language="C#">
    <msxml:assembly name="System.Web"/>
    <msxml:using namespace="System.Web.Security"/>
    <![CDATA[
    public bool UserIsInRole(string group)
    {
        if(Roles.IsUserInRole(group))
        {
           return true;
        }
        return false;
    }
    ]]>
    </msxml:script>

    <xsl:template match="/">

    <!-- start writing XSLT -->
    <xsl:if test="consea:UserIsInRole('Allowed')">
      <href="#">Your Link</a>
    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

     

    I hope this works for you.

    cheers

  • pushpendra 1 post 71 karma points
    Jun 27, 2016 @ 13:43
    pushpendra
    0

    There is a way to do this....Try following helpers......

    @Membership.GetUser() -- to get member name @Members.GetCurrentMemberId() -- to get member id @Roles.IsUserInRole("Group_Name") -- to know whether member is of this group or not

    I think it will work.

Please Sign in or register to post replies

Write your reply to:

Draft