You can do this with the PublicAccessService (docs)
you can get the rule for a current content item, GetEntryForContent:
var rule = publicAccessService.GetEntryForContent(contentItem);
or you can add rules first by creating a rule,
var rule = new PublicAccessEntry(contentItem, loginNode, noAccessNode, new List<PublicAccessRule>());
(you need to have a content node for the login page (loginNode), and one for the error/no access page (noAccessNode)).
then you can add rules to it.
rule.AddRule(ruleValue, ruleType);
Rule value will be the user/group and rule type is the type of rule.
rule type is either MemberUsername or MemberRole these are defined in Umbraco (so you can use these to be sure)
this should create a rule against a bit of content, rules inherit down, so if you do this on for example the homepage all rules beneath that will be protected.
Programmatically set permissions on node
Is there a way to Programmatically set permissions on node for a group? i.e. this group can only browse home, this group can browse, edit and create.
Is it possible to do this by pageAlias?
Hi Lori,
You can do this with the PublicAccessService (docs)
you can get the rule for a current content item, GetEntryForContent:
or you can add rules first by creating a rule,
(you need to have a content node for the login page (
loginNode
), and one for the error/no access page (noAccessNode
)).then you can add rules to it.
Rule value will be the user/group and rule type is the type of rule. rule type is either
MemberUsername
orMemberRole
these are defined in Umbraco (so you can use these to be sure)then you can save it
this should create a rule against a bit of content, rules inherit down, so if you do this on for example the homepage all rules beneath that will be protected.
is working on a reply...