Friday 25 October 2013

Master Page inheritance breaks Apps

Master Page inheritance breaks Apps


Setting the Master page and selecting "Reset all sub sites to inherit this site master page setting" will break all of your Apps!!!!








Error:
Accessing referenced file http://xxxxxxxxxxxxxxxxxx/_catalogs/masterpage/mymaster.master from http://xxxxxxxxxxxxxxxxxx/myapp................ is not allowed because the reference is outside of the App Web.

Exception Details: Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Accessing referenced file <Master Page URL> from <App URL> is not allowed because the reference is outside of the App Web.

Cause
If you have developed custom apps or have purchased apps from the App store and are using these on your SharePoint sites beware of using the "Reset all subsites to inherit this site master page setting" when setting the master page of your sites or if you have set the master page via deploying the . Stand alone apps need to inherit the App.master page.

Immediate Fix #1
Use this powershell script to set the App master page of your app.

Create a new file named setappmaster.ps1 in notepad and add the script below (OR YOU CAN DOWNLOAD THE POWERSHELL SCRIPT FILE FROM CODEPLEX)

https://setappmaster.codeplex.com/

Write-Host "----------Start of set app master page --------------"

$appsiteurl = $args[0]
$appweburl = $args[1]
try
{
$appsite = Get-SPSite $appsiteurl
$appweb = $appsite.OpenWeb($appweburl);
$appweb.CustomMasterUrl = "/" + $appweburl + "/_catalogs/masterpage/app.master"
$appweb.MasterUrl = "/" + $appweburl + "/_catalogs/masterpage/app.master"
$appweb.Update()
}
catch
{
Write-Host 'Error setting app.master'
}

Write-Host "----------End of set app master page --------------"

Run the new setappmaster.ps1 file in SharePoint 2013 Management Shell using the command below replacing the App Site and App Web URLs in bold with your own URLs

c:\powershell\setappmaster.ps1 'http://app-b77adfc321c0f.apps.com:9090/' 'MyApp'


Immediate Fix #2
Redeploy your apps to reset the master page back to App.master

Solution #1
You could use code and feature stapling to set your master page via the SharePoint API instead of using the standard Master Page Settings page, iterate through all sites and set the master page of each using an exception to check for isAppWeb and ignoring sites that are app webs.

Solution #2
When developing your custom apps change the master page url on all of the stand alone App pages to a fixed URL pointing to the App.master. This will cause problems if you plan on redistributing the app.

-------------------

If you have any comments or questions please give me a shout!

No comments:

Post a Comment

Comments Welcom!!