Hi!
Attach to the event CreatedPage, that should be raised after the page is created. If you update the ACL for the page there I can't see a reason why it would be overwritten.
Or perhaps this is one of the things that you've already tried that didn't work?
Regards
Per Gunsarfs
EPiServer CMS development team
Try to move:
newPage.ACL.Remove("CoachGroup");
newPage.ACL.Save();
to _after_ the call to DataFactory.Save()
/johan
Thanks for your suggestions, but...
@Per: It still does not do anything. The group that I removed is present on the page when I check its rights in edit mode.
@Johan: This throws an exception - Object reference not set to an object - on newPage.ACL.Save() . Same thing when I do newPage.ACL.CreateWriteableClone().Save();
Regards,
/Marten
OK, never mind.
Seems it works if I call DataFactory.Instance.GetPage on the newly created page and set the ACL from there. A bit strange that I can't set it directly on newPage, but at least it works now.
Thanks for the feedback.
/Marten
Look at the page in edit/admin mode for handling Access Control List.
Notice that you select lines that you want to add, edit or delete. So you have to Add what you want to delete to the ACL list.
PageAccessControlList acl = new PageAccessControlList(page.PageLink);
acl.Add(new AccessControlEntry("CoachGroup", AccessLevel.NoAccess, SecurityEntityType.Role));
acl.Save();
Notice that you must save the page and retreive it from the DataFactore to get a valid PageLink.
thanks, Fredrick. I have been banging my head against a wall with this one all evening!
Hello,
I am using CMS R2 SP2 to create a page programmatically, but I want the created page to NOT automatically receive all inherited rights and groups from the parent page.
In effect - I have a parent page with groups Administrators, Editors, CompanyGroup and CoachGroup - and I want the page created to just include the Administrators, Editors and CompanyGroup.
I have tried to set
PageData newPage = EPiServer.DataFactory.Instance.GetDefaultPageData(parentPageLink, pageTypeId);
newPage.PageName = "New Page";
...
DataFactory.Instance.Save(newPage, SaveAction.Publish);
I have tried within the "..." section to do this:
newPage.ACL.Remove("CoachGroup");
newPage.ACL.Save();
and I have tried to make a clone of the ACL like this:
AccessControlList myAcl = new AccessControlList(newPage.ACL.CreateWritableClone());
myAcl.Remove("CoachGroup");
myAcl.Save();
The former code block happily saves the ACL and it's gone while I debug, but on the next round or in edit mode the group that I don't want on this particular page is there again.
The latter code block throws an exception on myAcl.Save() that method is not supported.
I have tried some other approaches as well, such as grabbing a writeable clone of the page after the creation, and setting newPage.ACL.IsInherited = false, but the ACL won't budge.
Anyone have any ideas to share with me?
Thanks in advance,
/Marten