none
Find user permission to site in SharePoint Online using CSOM/JSOM.

    Question

  • Would it be possible to verify whether logged user has access to site if we pass URL of the Site in SharePoint Online?  

    I think SPContext in CSOM(JS) is bound to the site collection in which is called for.  We won’t be able to lookup information from an another site collection using SPContext in SP Online as its will always bound to Site Collection where script is executing. 

    Is it a limitation in SPO?

    Tuesday, February 28, 2017 4:36 PM

All replies

  • Hi,

    I tested with below code and we could build ClientContext for another site collection but the current user need have permission on target site otherwise it will give error.

    function retrieveWebSite(siteUrl) {
                var clientContext = new SP.ClientContext(siteUrl);
                this.oWebsite = clientContext.get_web();
    
                clientContext.load(this.oWebsite);
    
                clientContext.executeQueryAsync(
                    Function.createDelegate(this, this.onQuerySucceeded),
                    Function.createDelegate(this, this.onQueryFailed)
                );
            }
    
            function onQuerySucceeded(sender, args) {
                alert('Title: ' + this.oWebsite.get_title() +
                    ' Description: ' + this.oWebsite.get_description());
            }
    
            function onQueryFailed(sender, args) {
                alert('Request failed. ' + args.get_message() +
                    '\n' + args.get_stackTrace());
            }

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, March 1, 2017 2:53 AM
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, March 8, 2017 9:41 AM