0

I have to create custom action under standard menu(gear icon). Using below code I am able to create custom action on classic team site.

$siteAction = $context.Web.UserCustomActions.Add();
$siteAction.Group = "SiteActions";
$siteAction.Location = "Microsoft.SharePoint.StandardMenu";
$siteAction.Name = "Sample_CustomAction";
$siteAction.Sequence = 1000;
$siteAction.Url = $context.Url +"/_layouts/user.aspx"
$siteAction.Title = "Web Permissions";
$siteAction.Update();
$context.ExecuteQuery();

however, when tried the same code on modern team site, it says "Access denied. You do not have permission to perform this action or access this resource" I am able to access the site in browser. Please help.

0

It occurs because the Customize Pages right is denied by default on the modern site collection.

To resolve this issue, we need to Connect to SharePoint Online using PowerShell and set denyaddandcustomizepages of this site to false. DenyAddAndCustomizePages determines whether the Add And Customize Pages right is denied on the site collection.

$adminUPN="user@tenant.onmicrosoft.com"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."

Connect-SPOService -Url https://tenant-admin.sharepoint.com -Credential $userCredential
set-sposite https://tenant.sharepoint.com/sites/modernSite -denyaddandcustomizepages $false

After that, you can create custom site actions on the modern site using your commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.