More in this section

Forums / Developing with Sitefinity / Show Hide Content Blocks By Permission

Show Hide Content Blocks By Permission

4 posts, 0 answered
  1. Paul
    Paul avatar
    11 posts
    11 Jun 2013
    08 Oct 2013
    Link to this post
    I'd like to show hide my content blocks by permission, ie, certain users could see some content blocks while other roles or users can see all content blocks. Is this possible? If not, is there an alternative or the potential to expand widget?
  2. Jonathan
    Jonathan avatar
    119 posts
    19 Dec 2012
    08 Oct 2013 in reply to Paul
    Link to this post
    Warning!! I did not test this.  I created a class file in a folder called Custom in the webapp root.  The public string Roles should allow you to enter a comma separated list of allowed roles from the advanced section of the widget. You will also need to go into the toolboxes and override the ContentBlock widget in the toolboxes area. (see Screen Shot)

    using System;
    using System.Linq;
    using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
    using Telerik.Sitefinity.Security.Claims;
    using Telerik.Sitefinity.Security;
    namespace SitefinityWebApp.Custom
        public class ContentBlockOverride : ContentBlock
            protected string _roles = "Everyone";
            public string Roles
                get { return this._roles; }
                set { this._roles = value; }
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
                bool inRole = false;
                RoleManager roleManager = RoleManager.GetManager();
                var identity = ClaimsManager.GetCurrentIdentity();
                string[] _roles = Roles.Split(',');
                var role = roleManager.GetRoles().Where(r => r.Name == _roles[0].Trim()).FirstOrDefault();
                if (role != null)
                   inRole = roleManager.IsUserInRole(identity.UserId, role.Id);
                this.Visible = inRole;
  3. Tejal
    Tejal avatar
    7 posts
    26 Apr 2014
    03 Jul 2014
    Link to this post


     I have one content block and one custom module widget on page to show news. I have to show only one of them based on,which type of news admin wants to show. If admin wants the news from content block then widget should be hidden and vice versa. Can anyone help me on this, how I can take admin's choice of which news section to choose and how to hide other news section based on his choice.

    For better understanding of my question screenshot of page is attached here.


    Tejal Satre

  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    19 Apr 2017
    07 Jul 2014
    Link to this post
    Hello Tejal,

    For clarification and simplicity we have answered you in this forum thread which is more related to your question. Please, continue communication in it.

    Nikola Zagorchev
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
4 posts, 0 answered