etoisarobot
etoisarobot

Reputation: 7814

Setting Role Based Permission in code when saving new doc in Umbraco

I am using Umbraco 7.2.8. When a new Document of a specific type is saved, I am hooking into the ContentService.Saved event and I want to be able to set the Public Access to only allow a specific member group access to it. Just like I would do using the Gui here.

enter image description here

I see in the documentation here https://our.umbraco.org/documentation/Reference/Management/Services/ContentService There are a couple methods like

.AssignContentPermission(IContent content, char permission, IEnumerable userIds)

and

ReplaceContentPermissions(EntityPermissionSet permissionSet)

which both allow me to pass in a list of userIds users that have access but I am interested in setting the membership groups that have access as well as the Login Page and Error Page. How can I do this?

Upvotes: 0

Views: 517

Answers (1)

wingyip
wingyip

Reputation: 3536

Used to do it like this. I think it still applies:

Access.ProtectPage(false,nodeIdOfPageToProtect,loginPageNodeId,errorPageNodeId);
Access.AddMembershipRoleToDocument(nodeIdOfPageToProtect,"roleName");

Methods are in umbraco.cms.businesslogic.web so make sure you set this for your page

using umbraco.cms.businesslogic.web; 

Does that help?

Upvotes: 1

Related Questions