Quantcast
Channel: Mavention
Viewing all articles
Browse latest Browse all 627

Accessing referenced file MasterPage.master is not allowed because the reference is outside of the App Web.

$
0
0

​​​​​​​​​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

  1. Create a new site collection;
  2. Install any app from the app store;
  3. Check the app and confirm its working;
  4. Change the system masterpage, i.e. the default oslo, and check “Reset all subsites to inherit this system masterpage setting”;
  5. Try the app and see the (expected) error message.

​Explanation what happend

Once you deploy a App to the host web, you cannot change the master page of the AppWeb. As you can see in the Error, the masterpage is now linked to the host web masterpage instead of the App masterpage on its own App Web.
 
This issue can occur when you:
  • ​Change the system masterpage and reset all subsites to inherit this system masterpage;
  • Or a stapled event handler that changes the masterpages.
To fix the issue, you need to reset the masterpages to a masterpage located in their own AppWeb. Unfortunately, this cannot be done by using the interface. On-Premises you can use this quick PowerShell script or for Office365 you can use the CSOM approach.
 

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.


Viewing all articles
Browse latest Browse all 627

Trending Articles