Is it possible to set a property bag value via CSOM without having tenant permissions?

400 Views Asked by At

I'm trying to use my backend CSOM app with context of Site Collection Administrator service account to programmatically set a property bag value to store some settings for my frontend extension app.

I've tried doing it in 2 ways:

web.SetPropertyBagValue("name", "value");
ctx.ExecuteQuery();

and

web.AllProperties["name"] = "value";
web.Update();
ctx.ExecuteQuery();

but in both cases I get the error:

{"Access denied. You do not have permission to perform this action or access this resource."}

Is there really no way a Site Collection Administrator could set a property bag in SharePoint Online? I'm asking this because I've had similar issue when trying to delete a site, in which case according to a few sources on the Internet this operation could also be done only by tenant administrator but I found a method:

ctx.DeleteSiteAsync()

which turned out to be successfully deleting a site without tenant permissions. So I hope maybe there is also a solution here.

1

There are 1 best solutions below

1
Baker_Kong On

@Mariusz Ignatowicz

Just Test you code in my SPO modern site, It works fine here:

enter image description here

Then I enabled DenyAddAndCustomizePages as @m1g suggested, it will prompt "Access denied. You do not have permissio...."

Connect-SPOService -Url https://[tenant]-admin.sharepoint.com -credential [email protected]

Get-SPOSite -Identity https://[tenant].sharepoint.com/sites/comm|select DenyAddAndCustomizePages
### o is disable, 1 is enable
Set-SPOSite -Identity https://[tenant].sharepoint.com/sites/comm -DenyAddAndCustomizePages 1  

So i think you need to turn off DenyAddAndCustomizePages first, then it should be fixed.

BR