Show Hide Content Blocks By Permission
Hello,
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?
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)
base
.InitializeControls(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;
Hi,
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.
Thanks,
Tejal Satre
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.
Regards,
Nikola Zagorchev
Telerik