You may get this business requirement in the one following scenarios:
– You want to exclude part of a page (for example static links in the Master Page) from being indexed by SharePoint Search
– Just hide page elements for a specific user
For the Search scenario in SharePoint 2010 there is the possibility of using a div with CSS class name equal to noindex for not having the content crawled, but this doesn’t work in MOSS 2007.
<div class=”noindex”>content no to be indexed</div>
SharePoint has a build in feature which filters content based on the security roles of the user: SPSecurityTrimmedControl.
But the is no class for content trimming based on the loged-in user account, and we will create it :). The advantage is that this should work both in SharePoint 2010 and MOSS 2007.
Phase 1: Development
The C# class doesn’t contain more than:
public class SPUserSecurityTrimmedControl : SPSecurityTrimmedControl
public string ExcludeUser
protected override void Render(HtmlTextWriter output)
SPWeb site = SPContext.Current.Web;
if (site.CurrentUser.LoginName.ToLower() != ExcludeUser.Trim().ToLower())