Thursday, June 30, 2011

Role Based Content in Sharepoint Content Editor Web Part

The requirement here is: My client wants to show different contents in the content editor web part to Anonymous users and authorized users. To handle these kind of security trimming, we usually use "Security Trimming" in the master page.

But here, the end user doesn't want to place the content in master page, as it will repeat on every page. The requirement is targeted on ONLY one page. So, We need role based content inside SharePoint content editor web part.

Alright, Here is the solution for the issue:

Insert the below code to Master page: (You can insert just below <form runat="server" onsubmit="return _spFormOnSubmitWrapper();"> )

  var UserHasPermissions=false;

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ManageWeb">



Save & Publish the master page.

Now, In the content editor webpart on the target page,  place the below logic code.

if (UserHasPermissions)
  // Place the content for Logged-in user 

 //Place the content for anonymous user 

That's it, we are done.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:


  1. I get an error when the user is not authenticated. It does not understand what this "if (UserHasPermissions)" is because the user is not authenticated. Any ideas around this?

    1. That's the reason I'm using a variable "UserHasPermissions" instead of directly using functions! Send me your Master page code & Error!


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...