Displaying specific content only to site administrators

When working with intranet or extranet sites, as well as public-facing sites that allow users to log in, it is common to only allow administrators of the SharePoint site to see certain content. In this recipe, we will use our customized master page to hide content from users who are not site administrators.

How to do it...

Follow these steps to display specific content only to site:

  1. Open SharePoint Designer.
  2. Select Open Site. Enter the complete URL to the SharePoint site and select Open.
  3. From the Navigation pane, select Master Pages.
  4. In the list of files in the Master Pages library, make a copy of seattle.master (for our example, we have renamed it as Seattle_DisplayAdministratorContent.master).
  5. Check out the new Seattle_DisplayAdministratorContent.master master page.
  6. Open the Seattle_DisplayAdministratorContent.master master page.
  7. Locate the element with the ID_SuiteBarBrandingDelegate ID.
  8. After the delegate control, add a <SharePoint:SPSecurityTrimmedControl> control with the following content:
    <SharePoint:SPSecurityTrimmedControl ID="customSecurityTrimmedControl" PermissionContext="CurrentSite" PermissionsString="ManageWeb" runat="server">
    <span style="color: #FFFFFF; float: right;">Only Admins Can See This</span>
    </SharePoint:SPSecurityTrimmedControl>
  9. Save the master page.
  10. Check in and publish the master page using the Check In and Publish options.
  11. Set the master page as the Site Master Page.
  12. Navigate to the site in your preferred web browser as an administrator user and as a nonadministrator user to observe the results.

How it works...

The SPSecurityTrimmedControl is a simple server control that displays its content based on the permission levels of the current user. When this control renders, it simply looks to the current SharePoint context to determine if the current user has the permission level required.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.66.185