Monday, May 19, 2014

How to Hide Site Actions (or any control) Based on Permissions:

Hello Blog Readers!

It has been a while since I have had something interesting to write about, but I wanted to go ahead and post an article on how to hide the site actions button from those pesky users based on permission levels!

**Note hiding and disabling access are two different things.  The users would still be able to access the content if they knew the URL such as… path/_layouts/settings.aspx would still let them hit the site settings even if you hid the site actions control.**

In order to hide the control based upon permissions we will need:
  1.  SharePoint Designer
  2. This Code
    1. <SharePoint:SPSecurityTrimmedControl runat="server" Permissions=”DesiredLevel1,DesiredLevel2,etc”>
      <control to hide>
      </control to hide>
  3. A control you want to hide
For this example I want to hide the Site Actions from every page in my site, so I will be editing the Master Page.

  1. Open SharePoint Designer
  2. Connect To Your Site
  3. Under Navigation
  4.  Select Master Pages
    1. Select The Desired Master Page
  5. Right Click The Master Page & Select Edit in Advanced Mode
  6. Check Out The Page
After completing steps 1 through 6, we should be ready to wrap the ms-siteactionsmenu span

 <span class="ms-siteactionsmenu" id="siteactiontd">

with our security control in order to hide it based upon permissions.  When we wrap this span in the security trim make sure to find the span's corresponding end tag (</span>).  Depending on how your master page is set up, it could be 30, 50, 100 lines down from your opening span tag.  I typical do a find and search for </span> which typically makes it painless to find.

Now the fun part, lets wrap the span in our security trim control! For the sake of space, I am not including all of my code which would be in between the span.  Instead I am using a very technical note to represent it, aka "Tons of master page code here".

The next step is easy, above your span input

<SharePoint:SPSecurityTrimmedControl runat="server" Permissions=”DesiredLevel1,DesiredLevel2,etc”>
span class="ms-siteactionsmenu" id="siteactiontd">
"Tons of master page code here"

Finally, replace the desired permission level placeholders with the permission levels which are allowed to view and use the hidden control.  The link below has the exhaustive list to choose from.

After you have input the desired permissions, save the updates, check in the page, and publish it if necessary.  I hope this article was able to help and feel free to leave a comment if there are any issues!


No comments:

Post a Comment