Tip 12: Hide in plain view with SharePoint:SPSecurityTrimmedControl
This tip is for Windows SharePoint Services 3.0 and Microsoft Office SharePoint Server 2007 and may apply to SharePoint Foundation 2010 and SharePoint Server 2010.
To celebrate my watching of a classic ninja movie last night; I thought my next tip should be about helping “Ninjaize” your site.
Did you know that the SharePoint control; <SharePoint:SPSecurityTrimmedControl> can hide parts of a page from users without certain permissions? Say I have a SharePoint Internet site and I want to hide the Quick Launch navigation, which are the links on the left-hand side of a SharePoint site with the blank or team template, for all users except for site administrators. All I need to do is open up the site in SharePoint Designer and open the master page for the default.aspx page which is /_catalogs/masterpage (Master Page Gallery)/default.master.
After the master page is loaded, click on the quick launch and switch to code view from the bottom and add the following line before the lines that are highlighted:
<SharePoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ManageWeb” >
I put it before the following line:
<asp:ContentPlaceHolder id=”PlaceHolderLeftNavBar” runat=”server” >
Then add the following after the close of the ContentPlaceHolder:
</SharePoint:SPSecurityTrimmedControl>
The PermissionsString property is the permission that will be needed on the site for the controls inside of the SharePoint:SPSecurityTrimmedControl to render. A list of the permissions are located here. The above example will also hide the “View All Site Content” link which will help if you are trying to build a clean looking home page and do not need visitors of your site to navigate directly to the lists and document libraries of the site.
So remember if you are changing the look of your pages you can give different users more or less functionality based on their security permissions using the <SharePoint:SPSecurityTrimmedControl>.