Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
In addition:
The code is fired through a button click. If i have f.ex two users that i want to remove, the first one is removed when i click the button. but i have to click the button again to remove the last one.
Anyone got a clue?
-Kjetil Simensen
Solved!
After a lot of try and errors I finally managed to get this thing to work! My mistake in the initial code might be obvious (maybe that's why nobody came to my rescue, hehe) but I am very pleased nevertheless. The mistake was that I created a new writableclone of the ACL list for each user and saved it, instead of only creating one writeableclone before my "foreach" loop and save it afterward. Looking back I'm a bit embarrassed for not trying this earlier...
The final code:
AccessControlList writeList = page.ACL.CreateWritableClone();
foreach (string user in users)
{
if (writeList .Exists(user))
{
AccessControlEntry entry = new AccessControlEntry(user, AccessLevel.NoAccess, SecurityEntityType.User);
writeList[user] = entry;
}
}
writeList.Save();
-Kjetil Simensen
Hi,
I am trying to delete or set NoAccess on a set of users programatically. My problem is that my code works fine for 1 user but when i try the same code on multiple users only one of them are set to NoAccess. Anyone else had this problem? Using CMS 5.
My code:
foreach (string user in users)
{
if (page.ACL.Exists(user))
{
AccessControlList writeList = page.ACL.CreateWritableClone();
AccessControlEntry entry = new AccessControlEntry(user, AccessLevel.NoAccess, SecurityEntityType.User);
writeList[user] = entry;
writeList.Save();
}
}