Hide ribbon using SPSecurityTrimmedControl

In one of my current SharePoint 2010 Foundation projects I needed to hide ribbon from anonymous users. Visitors, contributors etc must see ribbon on all pages where it shown by default. In this posting I will show you how to hide ribbon using SPSecurityTrimmedControl.

Solution is simple. Open master page where you want to hide ribbon and search for the following line (if your master page is v4 default or based on this):


<div id=“s4-ribbonrow” class=“s4-pr s4-ribbonrowhidetitle”>


Embed all this div to its closing tag with SPSecurityTrimmedControl like shown here:


<SharePoint:SPSecurityTrimmedControl PermissionsString=“EditListItems” runat=“server”>
    <div id=“s4-ribbonrow” class=“s4-pr s4-ribbonrowhidetitle”>
        …
    
</div>
</SharePoint:SPSecurityTrimmedControl
>


PermissionsString attribute allows you to specify which permissions user must have at least to see ribbon. You can find available values for permission strings from MSDN page SPBasePermissions Enumeration. Take a look at table on this page. Member name column shows you possible values.

You can use SPSecurityTrimmed control also in other parts of master pages and page layouts where you want to hide some content from users with not enough permissions.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    Leave a Reply

    Your email address will not be published. Required fields are marked *