3

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 https://microsoft-e25da8eeaa88f2.sharepoint.com/teams/NaveenDevSite/_catalogs/masterpage/seattle.master from https://microsoft-e25da8eeaa88f2.sharepoint.com/teams/NaveenDevSite/FinanceConfigApp/Pages/Default.aspx?SPHostUrl=https://microsoft.sharepoint.com/teams/NaveenDevSite&SPLanguage=en-US&SPClientTag=3&SPProductNumber=15.0.4454.1026&SPAppWebUrl=https://microsoft-e25da8eeaa88f2.sharepoint.com/teams/NaveenDevSite/FinanceConfigApp 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('https://microsoft.sharepoint.com/teams/NaveenDevSite');
    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');
    web.update();

    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());

    });
}
3
  • can you post your code? Make sure you are changing the master page for the site collection and not the system master page. Commented Mar 27, 2013 at 1:16
  • Thanks, I have pasted my script above which can set both site and system master page of site coll...
    – nks
    Commented Mar 27, 2013 at 7:05
  • Did you give permissions to the app so that it can access resources outside the App web. Commented Dec 25, 2013 at 5:48

1 Answer 1

1

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: http://sharepointquicksolutions.blogspot.com/2013/01/get-host-web-url-in-sharepoint-2013-apps.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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