Freigeben über


The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again

Calling BreakRoleInheritance(false)on a List, internally flips the AllowUnsafeUpdates flag to false, and this may lead to below mentioned error, if we do not explicitly set the AllowUnsafeUpdates to true again.

When any object that implements ISecurable (those are SPWeb, SPList and SPListItem) breaks or reverts their role definition inheritance. This means every time you call
SPRoleDefinitionCollection.BreakInheritance(), BreakRoleInheritance(), ResetRoleInheritance() or set the value of HasUniquePerm the AllowUnsafeUpdates
property of the parent web will reset to its default value and you may need to set it back to true in order to do further updates to the same objects.

Therefore, it can be safely concluded that , if we intend to do SPWeb and SPSite modifications after a call to BreakRoleInheritance for a List, a recommended usage
is to couple it with an explicit setting of AllowUnsafeUpdates property to true for the web & site again.

Attaching Sample code

---------------------------------------

SPSite objSPSite = new SPSite("<ServerURL>");
SPWeb objSPWeb = objSPSite.OpenWeb(objSPSite.OpenWeb().ID);
SPListCollection lists = objSPWeb.Lists;

Guid docLibGuid = lists.Add("Doc Lib 1", "Doc Lib Desc", SPListTemplateType.DocumentLibrary);

SPList docLib = lists[docLibGuid];
docLib.EnableVersioning = true;
docLib.OnQuickLaunch = true;
docLib.Update();

objSPWeb.AllowUnsafeUpdates = true;

docLib.BreakRoleInheritance(false); //Exception is thrown in this line of code.
docLib.Update();

When we remove docLib.BreakRoleInheritance(false) everything works fine.

Will have to change the last two lines of code as below

docLib.BreakRoleInheritance(false); //Exception is thrown in this line of code.
objSPWeb.AllowUnsafeUpdates = true;
docLib.Update();

Comments

  • Anonymous
    December 30, 2008
    The comment has been removed

  • Anonymous
    December 18, 2013
    hey, though you faced this issue in 2008, I got to face this at the end of 2013 and am on SP 2010. firstly, thanks for helping me out with this valuable info. But I have a small question or need some clarification here. I am breaking the inheritance of subsites and resetting them and in that context what you said is absolutely correct and worked after I added one more allowunsafeupdates=true. I am also doing the same on a list item (inheriting if broken and then breaking again) and in this context, I have only one allowunsafeupdates=true at the begining and I am not thrown exception there. So, am not sure if this scenario applies for list items or not. I didn't try this against lists. once again, thanks for educating me on something I don't know.

  • Anonymous
    May 06, 2014
    The comment has been removed

  • Anonymous
    December 30, 2014
    You must DEFINITELY remember to set the AllowUnsafeUpdates to false after the update, so: objSPWeb.AllowUnsafeUpdates = true; docLib.Update(); objSPWeb.AllowUnsafeUpdates = false;