Wednesday, July 4, 2012

Hide the ribbon control for the anonymous user


Hello  ,


Today we will hide the ribbon control for the anonymous users.Generally when we configured the anonymous access in the SharePoint site , the ribbon control is also visible but we do not want to show the same for the anonymous user.so we will use some JavaScript trick and SharePoint permission feature.
so lets we start.


First open your master page.
we will by default hide the ribbon control division tag , so for that find the ribbon control division id "s4-ribbonrow" and make the division to display none by applying the style and add the following tag after completion of the ribbon division element.


<Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControlAnonymousUser" runat="server" PermissionsString="AddAndCustomizePages">
<script type="text/javascript">
  document.getElementById("s4-ribbonrow").style.display = "block";
</script>
</Sharepoint:SPSecurityTrimmedControl>


The final tag will be look like as shown below


<div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle"style="display:none">
   Ribbon control content.
</div>
<Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControlAnonymousUser" runat="server" PermissionsString="AddAndCustomizePages">
<script type="text/javascript">
  document.getElementById("s4-ribbonrow").style.display = "block";
</script>
</Sharepoint:SPSecurityTrimmedControl>


Here , the user who is having the permission of adding the page and customized the page can only view the ribbon.


Next save the masterpage and published it.so the ribbon will be hide for the anonymous user.
If you want to display the sign in button for the anonymous user you need to remove the 
welcome control from the ribbon division to some where else as per your UI requirement.


Find the below tag from the ribbon division element and place it to some other location as per your requirement.
<wssuc:Welcome id="IdWelcome" runat="server" EnableViewState="false"></wssuc:Welcome>


Regards
Hiren Patel




No comments:

Post a Comment