SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In SharePoint 2013 Developer Site:

I am installing an app to my site and it worked fine with default stuff. I added some custom .js file in this app which will set the master page of site coll and deployed again. I am able to open it once, but not able to set the master page. And from 2nd time onwards it always gives be below error:

**Sorry, there was a problem with FinanceConfigApp

For support, please contact the developer. Accessing referenced file from is not allowed because the reference is outside of the App Web.**

Any help would be highly appreciated!!!

I have tried: hardcoded the client context like below:

context = new SP.ClientContext('/teams/NaveenDevSite');
context = new SP.ClientContext('');
    context = new SP.ClientContext.get_current();

below is the complete code which works perfect in my page. but not in App:

$(document).ready(function () {
    jQuery('.cmdSet').click(function () {

        var scriptBase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";

        $.getScript(scriptBase + "sp.runtime.js", function () {

            $.getScript(scriptBase + "sp.js", function () {

                $.getScript(scriptBase + "sp.core.js", sharePointReady);



var context;
var web;
var masterurl;
var site;
function sharePointReady() {
    context = new SP.ClientContext.get_current();
    web = context.get_web();

    context.load(web, 'ServerRelativeUrl');
    var splitBaseUrl = L_Menu_BaseUrl.split('/');
    var baseUrl = '/' + splitBaseUrl[1] + '/' + splitBaseUrl[2];
    web.set_customMasterUrl(baseUrl + '/_catalogs/masterpage/seattle.master');
    web.set_masterUrl(baseUrl + '/_catalogs/masterpage/seattle.master');

    context.executeQueryAsync(function () {
        masterurl = web.get_serverRelativeUrl() + "/_catalogs/masterpage/seattle.master";
        alert("Master Page is Set Successfully!!!");

    }, function (sender, args) {

        alert("Error: " + args.get_message());

share|improve this question
can you post your code? Make sure you are changing the master page for the site collection and not the system master page. – Ryan Erickson Mar 27 '13 at 1:16
Thanks, I have pasted my script above which can set both site and system master page of site coll... – nks Mar 27 '13 at 7:05
Did you give permissions to the app so that it can access resources outside the App web. – Nadeem Yousuf Dec 25 '13 at 5:48

Try putting: context.load(web, 'ServerRelativeUrl');

after you perform web.update()

As per your error, you might have to read SPHostUrl from the parameters.

See this:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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