Masterpage inheritance will break your apps. Setting you want to reset or change the masterpage of the site and all its subsite. This works all fine like you expect to, until you open a SharePoint Add-in and you get errors.
Web Error
Sorry, something went wrong Accessing referenced file http://app-27798620f05bf1.appdomain.com/sites/publication/_catalogs/masterpage/seattle.master from http://app-27798620f05bf1.appdomain.com/sites/publication/Pages/Default.aspx?SPHostUrl=http://spserver/sites/publication&SPLanguage=en-US&SPClientTag=14&SPProductNumber=15.0.4420.1017&SPAppWebUrl=http://app-27798620f05bf1.appdomain.com/sites/publication is not allowed because the reference is outside of the App Web. |
ULS Error
Application error when access /publication/Pages/Default.aspx, Error=Accessing referenced file https://app-27798620f05bf1.appdomain.com/_catalogs/masterpage/seattle.master from https://app-27798620f05bf1.appdomain.com/publication/Pages/Default.aspx?SPHostUrl=https:// spserver/sites/publication&SPLanguage=en-US&SPClientTag=14&SPProductNumber=15.0.4420.1017&SPAppWebUrl=https://app-27798620f05bf1.appdomain.com/sites/publication is not allowed because the reference is outside of the App Web. |
Steps to re-produce
- Create a new site collection;
- Install any app from the app store;
- Check the app and confirm its working;
- Change the system masterpage, i.e. the default oslo, and check “Reset all subsites to inherit this system masterpage setting”;
- Try the app and see the (expected) error message.
Explanation what happend
- Change the system masterpage and reset all subsites to inherit this system masterpage;
- Or a stapled event handler that changes the masterpages.
Fixing with PowerShell
$prefix = "spapp" $allappurls = Get-SPSite | Get-SPWeb -Limit All | where {$_.url -like "http://$prefix*"} foreach ($app in $allappurls) { $name = $app.name $app.CustomMasterUrl = "/$name/_catalogs/masterpage/app.master" $app.MasterUrl = "/$name/_catalogs/masterpage/app.master" $app.Update() }
Fixing with CSOM
add-type -Path 'Microsoft.SharePoint.Client.dll' $siteurl = 'https://mavention-27798620f05bf1.sharepoint.com/publication/' $username = 'admin@mavention.onmicrosoft.com' $password = Read-Host –Prompt ‘Enter Password’ -AsSecureString try { $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $context.Credentials = $credentials $site = $context.Site $web = $site.OpenWeb('Publication') $web.CustomMasterUrl = "/Publication/_catalogs/masterpage/app.master" $web.MasterUrl = "/Publication/_catalogs/masterpage/app.master" $web.Update() $context.ExecuteQuery() } catch { Write-Host -ForegroundColor Red 'Error when trying to set app master url on ' $siteurl, ':' $Error[0].ToString() }
No-code fix
You can also redeploy all your apps to reset the masterpage back to the (original) app.master.