With sharepoint 2010 came the famous Ribbon Control. It provides a very rich user interface and is very sleek looking as well. By putting the most needed and used collaboration functions on the ribbons , Microsoft has given both boon and curse. Boon because,everything is on your fingertips. Curse because , you don't want unauthorized users to use them and the solution is not very obvious, but easy. I will explain how to easily hide unnecessary ribbon controls from unauthorized users.
I won't explain the ribbon architecture here as you may find it's documentation easily. You can find one at
It has a brief introduction to architecture.
You can download the code here
1) First Let us start by creating an empty sharepoint project in visual studio 2010.
2) Now right click on the solution in the solution explorer and select Add->Add a sharepoint mapped folder
3) Select TEMPLATES-> CONTROLTEMPLATE
4) Now again right click on this mapped folder and add another folder. This is because when you deploy the solution the user control will be deployed to the control templates folder in templates in 14 hive. Now there are a lot of controls and dlls in this folder. To differentiate them we make a folder.
5) Now right click on this folder and add an user control. Now you need to reference some dlls. Microsoft.Web.CommandUI.
6) Now the SPRibbon control can be found in Microsoft.SharePoint.WebControls . Now the next part of the solution is to get the names of the controls to be hidden. We can find this here->
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML
Also you can map the names given in this file to Ribbon Documentation.
7) Now Suppose you want to hide the controls for users with a certain roles.
for eg: I have created a custom role called ForPageContributors. Now I want to hide controls from users having this role only. If they have other roles also like Approve,Full Control or Contribute,they can see even if they have custom role.
8) Just add the following code to the user control.
IsUserAuthorized checks if user has authorization.
9) Now just save the solution and right click the solution and select deploy.
10) Open the master page in sharepoint designer and register this user control there. And just make a call to it in the body section. Save it and do an IISRESET. When you will sign into your site with a user having above mentioned role, he will not see the Controls hidden from code. Whereas others will see them.