0

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.

Mariusz Ignatowicz
  • 1,445
  • 2
  • 20
  • 41
  • This is doable. I assume your likely using a Modern site? These have noscript enabled by default and prevent any programmatic access while enabled. You can turn off noscript however, wait until applied, then update the property bag and then disable. I believe this is actually exposed as property 'DenyAddAndCustomizePages' and does take a few seconds to fully disable. – m1g Dec 31 '20 at 03:06

1 Answers1

0

@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 admin@tenant.onmicrosoft.com

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

Baker_Kong
  • 1,739
  • 1
  • 4
  • 9