Home

Access denied in SharePoint SitePages library

%3CLINGO-SUB%20id%3D%22lingo-sub-77891%22%20slang%3D%22en-US%22%3EAccess%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77891%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20create%20modern%20SharePoint%20pages%20programmatically%20in%20SitePages%20libraries%20on%20groups-based%20sites.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20first%20attempted%20doing%20so%20with%20PowerShell%2C%20then%20with%20Flow%20and%20finally%20confirmed%20via%20a%20direct%20call%20to%20the%20REST%20service%20that%20it%20is%20not%20supported--%20in%20each%20case%2C%20the%20result%20is%20the%20same%3A%20Access%20Denied.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20policy%20on%20modern%20SharePoint%20SitePages%20libraries%20that%20prevents%20users--%20even%20users%20with%20full%20control%20of%20the%20site--%20from%20creating%20content%20via%20REST%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20the%20result%20of%20the%20REST%20post%20to%20%2Ffiles%2Fadd%20method%3A%3C%2FP%3E%3CDIV%20class%3D%22container%22%3E%3CDIV%20class%3D%22ng-scope%22%3E%3CDIV%20class%3D%22subsection-manage%20ng-scope%22%3E%3CDIV%20class%3D%22row%22%3E%3CDIV%20class%3D%22column%22%3E%3CDIV%20class%3D%22msla-container%20msla-host-processsimple%22%3E%3CDIV%20class%3D%22ms-Fabric%20ms-font-m%22%3E%3CDIV%20class%3D%22msla-monitor-container%22%3E%3CDIV%20class%3D%22msla-monitor-canvas%22%3E%3CDIV%20class%3D%22msla-designer-canvas-parallel%22%3E%3CDIV%20class%3D%22msla-card-container%22%3E%3CDIV%20class%3D%22msla-card-flex%22%3E%3CDIV%20class%3D%22msla-card-view-div%22%3E%3CDIV%20class%3D%22msla-card-view%22%3E%3CDIV%20class%3D%22msla-card-children%22%3E%3CDIV%20class%3D%22msla-card-container%22%3E%3CDIV%20class%3D%22msla-card-flex%22%3E%3CDIV%20class%3D%22msla-card-view-div%22%3E%3CDIV%20class%3D%22msla-card-view%22%3E%3CDIV%20class%3D%22msla-card-caption%22%3E%3CDIV%20class%3D%22msla-card%20msla-monitoring-card%20msla-card-selected%20msla-card-fixed-width%22%3E%3CDIV%20class%3D%22msla-card-body%22%3E%3CDIV%20class%3D%22msla-monitoring-parameters-card-body%22%3E%3CDIV%20class%3D%22msla-trace-values%22%3E%3CDIV%3E%3CDIV%20class%3D%22msla-trace-value-text%22%3E%7B%20%22status%22%3A%20403%2C%20%22message%22%3A%20%22Access%20denied.%20You%20do%20not%20have%20permission%20to%20perform%20this%20action%20or%20access%20this%20resource.%22%2C%20%22source%22%3A%20%22https%3A%2F%2F%3CMYTENANTURL%3E.sharepoint.com%2Fsites%2F%3CSITENAME%3E%2F_api%2Fweb%2FGetFolderByServerRelativeUrl('%2Fsites%2FSafety%2FSitePages')%2Ffiles%2Fadd(url%3D'Test9.aspx'%2C%2520overwrite%3D'true')%22%2C%20%22errors%22%3A%20%5B%20%22-2147024891%22%2C%20%22System.UnauthorizedAccessException%22%20%5D%20%7D%3C%2FSITENAME%3E%3C%2FMYTENANTURL%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%22-2147024891%22%2C%20%22System.UnauthorizedAccessException%22%20%5D%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20appears%20related%20to%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fissues%2F819%23issuecomment-295660778%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20same%20issue%20that%20I%20posted%20to%20the%20PnP%20GitHub%20repo%3C%2FA%3E%2C%20in%20which%20the%20same%20occurs%20when%20attempting%20to%20upload%20a%20page%20via%20PowerShell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPer%20this%20post%20by%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5720%22%20target%3D%22_blank%22%3E%40Vesa%20Juvonen%3C%2FA%3E%2C%20the%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Fpnp_articles%2Fmodern-experience-customizations-customize-pages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eclient%20object%20model%20supports%20adding%20pages%20programmatically%20%3C%2FA%3Eand%20there%20are%20PnP%20extension%20methods%20to%20do%20so.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ETL%3BDR%3A%20%3C%2FSTRONG%3EJust%20want%20to%20confirm%20that%20the%20same%20is%20NOT%20possible%20via%20REST%20at%20this%20time%20as%20it%20will%20affect%20the%20architecture%20of%20a%20solution%20I'm%20writing.%3C%2FP%3E%3CDIV%20class%3D%22container%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-77891%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394475%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394475%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301719%22%20target%3D%22_blank%22%3E%40GlennE888%3C%2FA%3E%26nbsp%3BSounds%20like%20the%20source%20of%20the%20page%20might%20be%20messed%20up%3F%20It%20might%20be%20worth%20opening%20a%20new%20ticket.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394114%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394114%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F75637%22%20target%3D%22_blank%22%3E%40Jonathan%20Cardy%3C%2FA%3E%3C%2FP%3E%3CP%3EThanks%2C%20I%20got%20it%20working%2C%20I%20was%20pointing%20to%20the%20folder%20where%20I%20wanted%20to%20place%20the%20file%20instead%20of%20pointing%20to%20the%20file%20I%20wanted%20to%20be%20created.%20So%20I%20now%20am%20able%20to%20create%20pages%20on%20the%20site%20but%20still%20having%20problems%20with%20the%20pages%20created.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EIf%20I%20create%20the%20page%20in%20Site%20Pages%2C%20then%20try%20to%20edit%20them%20from%20the%20UI%20I%20get%3A%3C%2FP%3E%3CP%3E%22You%20cannot%20edit%20this%20page%3C%2FP%3E%3CP%3EWe're%20sorry%2C%20we%20encountered%20an%20unexpected%20error.%20Please%20try%20again%2C%20if%20the%20problem%20persists%20please%20contact%20your%20Administrator.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20create%20the%20page%20in%20WikiPageLib%2C%20I%20can't%20even%20load%20the%20file.%20Attempting%20to%20load%20the%20file%20I%20get%3A%3C%2FP%3E%3CP%3E%22Sorry%2C%20something%20went%20wrong%3CBR%20%2F%3ENoComponentId%22%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAny%20ideas%3F%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-376813%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-376813%22%20slang%3D%22en-US%22%3EI'm%20using%20Office365.%20I%20haven't%20tried%20it%20on%20premise%20as%20of%20yet%20but%20I%20believe%20the%20solution%20is%20the%20same.%20PnP%20does%20actually%20use%20this%20same%20method%20-%20compare%20your%20code%20to%20that.%20Source%20is%20here%20-%20search%20for%20'AddTemplateFile'%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fblob%2Fmaster%2FCore%2FOfficeDevPnP.Core%2FPages%2FClientSidePage.cs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fblob%2Fmaster%2FCore%2FOfficeDevPnP.Core%2FPages%2FClientSidePage.cs%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-376809%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-376809%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F75637%22%20target%3D%22_blank%22%3E%40Jonathan%20Cardy%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20response.%26nbsp%3B%20Is%20your%20Sharepoint%20OnPremise%20or%20Office365%3F%26nbsp%3B%20I'm%20trying%20to%20upload%20to%20Office365%20and%20with%20the%20example%20given%20I%20continue%20to%20get%20%22Access%20denied.%20You%20do%20not%20have%20permission%20to%20perform%20this%20action%20or%20access%20this%20resource.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20giving%20OfficeDevPnP.Core.Pages%20a%20try%20and%20am%20having%20a%20bit%20more%20luck%20with%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-374178%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-374178%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301719%22%20target%3D%22_blank%22%3E%40GlennE888%3C%2FA%3E%26nbsp%3Byes%20it%20worked%20for%20me!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-370236%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-370236%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F75637%22%20target%3D%22_blank%22%3E%40Jonathan%20Cardy%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20that%20work%20for%20you%3F%26nbsp%3B%20I%20tried%20to%20add%20the%20page%20via%20Files.AddTemplateFile%20as%20mentioned%20but%20I%20get%20the%20same%20Access%20Denied%20Error.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-327912%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-327912%22%20slang%3D%22en-US%22%3E%3CP%3ETrying%20to%20upload%20an%20aspx%20file%20directly%20will%20raise%20the%20Access%20Denied%20error%2C%20but%20you%20can%20use%20the%20%60%3CSPAN%3EFiles.AddTemplateFile%60%20method%20do%20it%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsolution-guidance%2Fmodern-experience-customizations-customize-pages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsolution-guidance%2Fmodern-experience-customizations-customize-pages%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-174213%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-174213%22%20slang%3D%22en-US%22%3E%3CP%3EI%20had%20the%20same%20issue%20trying%20with%20CSOM...%20Any%20solution%3F%3C%2FP%3E%0A%3CP%3EWhat%20I%20saw%20in%20the%20permissions%20is%20that%20there%20is%20a%20DENY%20...%20Another%20indicator%20that%20something%20is%20blocking%20us...%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F30700i76B21C593823349F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Deny.png%22%20title%3D%22Deny.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EDeny%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78254%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78254%22%20slang%3D%22en-US%22%3EThanks%20for%20double-checking%20me.%20One%20comment%20on%20my%20PnP%20query%20suggested%20that%20this%20is%20intentional%20to%20prevent%20developers%20from%20uploading%20ASPX%20pages.%20Not%20sure%20if%20this%20is%20the%20case%20or%20not%3B%20hoping%20we%20can%20get%20some%20kind%20of%20confirmation%20from%20Microsoft.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78250%22%20slang%3D%22en-US%22%3ERe%3A%20Access%20denied%20in%20SharePoint%20SitePages%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78250%22%20slang%3D%22en-US%22%3E%3CP%3EJust%20tried%20this%20on%20my%20tenant%2C%20I%20can%20upload%20via%20REST%26nbsp%3Bto%20Site%20Pages%20on%20classic%20sites%2C%20I%20get%20the%20same%20behaviour%20as%20you%20describe%20when%20trying%20on%20a%20Modern%20site.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Christopher Johnson
Contributor

I am trying to create modern SharePoint pages programmatically in SitePages libraries on groups-based sites.

 

I first attempted doing so with PowerShell, then with Flow and finally confirmed via a direct call to the REST service that it is not supported-- in each case, the result is the same: Access Denied.

 

Is there a policy on modern SharePoint SitePages libraries that prevents users-- even users with full control of the site-- from creating content via REST?

 

Below is the result of the REST post to /files/add method:

{ "status": 403, "message": "Access denied. You do not have permission to perform this action or access this resource.", "source": "https://<myTenantUrl>.sharepoint.com/sites/<siteName>/_api/web/GetFolderByServerRelativeUrl('/sites/Safety/SitePages')/files/add(url='Test9.aspx',%20overwrite='true')", "errors": [ "-2147024891", "System.UnauthorizedAccessException" ] }

"-2147024891", "System.UnauthorizedAccessException" ] }

 

This appears related to the same issue that I posted to the PnP GitHub repo, in which the same occurs when attempting to upload a page via PowerShell.

 

Per this post by @Vesa Juvonen, the client object model supports adding pages programmatically and there are PnP extension methods to do so. 

 

TL;DR: Just want to confirm that the same is NOT possible via REST at this time as it will affect the architecture of a solution I'm writing.

 
10 Replies

Just tried this on my tenant, I can upload via REST to Site Pages on classic sites, I get the same behaviour as you describe when trying on a Modern site.

Thanks for double-checking me. One comment on my PnP query suggested that this is intentional to prevent developers from uploading ASPX pages. Not sure if this is the case or not; hoping we can get some kind of confirmation from Microsoft.

I had the same issue trying with CSOM... Any solution?

What I saw in the permissions is that there is a DENY ... Another indicator that something is blocking us...


Deny.pngDeny

Trying to upload an aspx file directly will raise the Access Denied error, but you can use the `Files.AddTemplateFile` method do it: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/modern-experience-customizations-c...

@Jonathan Cardy 

 

Does that work for you?  I tried to add the page via Files.AddTemplateFile as mentioned but I get the same Access Denied Error.

@GlennE888 yes it worked for me!

@Jonathan Cardy Thanks for the response.  Is your Sharepoint OnPremise or Office365?  I'm trying to upload to Office365 and with the example given I continue to get "Access denied. You do not have permission to perform this action or access this resource."

 

I'm giving OfficeDevPnP.Core.Pages a try and am having a bit more luck with that.

I'm using Office365. I haven't tried it on premise as of yet but I believe the solution is the same. PnP does actually use this same method - compare your code to that. Source is here - search for 'AddTemplateFile': https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Pages/ClientSidePage...

@Jonathan Cardy

Thanks, I got it working, I was pointing to the folder where I wanted to place the file instead of pointing to the file I wanted to be created. So I now am able to create pages on the site but still having problems with the pages created.


If I create the page in Site Pages, then try to edit them from the UI I get:

"You cannot edit this page

We're sorry, we encountered an unexpected error. Please try again, if the problem persists please contact your Administrator."

 

If I create the page in WikiPageLib, I can't even load the file. Attempting to load the file I get:

"Sorry, something went wrong
NoComponentId"


Any ideas?


Thanks.

@GlennE888 Sounds like the source of the page might be messed up? It might be worth opening a new ticket.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
21 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies