GetAllSubWebCollection Access Denied

Jun 14, 2012 at 6:42 AM

I have a folowing code:

$().SPServices({
 operation: "GetAllSubWebCollection",
webURL: "/", 
async: false, 
completefunc: function (xData, Status) {

}
});

If user don't have permission on one or more Site, he has an error, and he can't get other site where he have permission. 

How can i get sites where user have Read or Write permission?

Jun 14, 2012 at 6:15 PM

I think you can wrap this in a javascript try/catch block and it should work. I have had to do this for the same reasons.

Jun 18, 2012 at 11:24 AM

I tried it. May be there is another way to get around all the sites available to the user?

Coordinator
Jun 18, 2012 at 6:53 PM

To use this operation, the user must have permission to iterate over the sites in the Site Collection. The only way around it that I know of is to give them that permission.

M.

Jun 19, 2012 at 11:46 AM

Usually, this only seems to work for me when I use a try/catch. If the user does not have access to a site, it should skip to the next one. I will see if I can find the code that I used. I also agree with Marc that they need to have permission to enumerate the sites even if they don't have access to a specific site.

Jun 19, 2012 at 1:56 PM

To use the GetAllSubWebCollection you need to add a custom permission level allowing users to "Browse Directories" as mentioned. The problem there (I think) is that that will also return sites where they don't have permissions. One ugly workaround for the GetWebCollection without changing permission levels could be to get the sites from the viewlsts.aspx, somehting like below. That should handle the permissions better.

function getSites(url){
	$.get(url, 
		{ShowSites: 1, isdlg: 1},
		function(data){
	     		$(data).find("#webUrl").each(function() {
				$("body").append($(this).text()+'-'+$(this).attr('href')+'<br>');
			});
	    	}
	);
}

$(document).ready(function() {
  	getSites('http://yoursite/_layouts/viewlsts.aspx');
});

A workaround for GetAllSubWebCollection could be to put a "Site Tree View" web part on an empty page on site collection level and get the sites from there also using the $.get function

/Fredrik

Dec 5, 2013 at 3:08 PM
sympmarc wrote:
To use this operation, the user must have permission to iterate over the sites in the Site Collection. The only way around it that I know of is to give them that permission. M.
Hey there I have parseerror returned in the Status and xData returned is undefined when I signin as a contributor. The user has sharepoint Contributor (which by default has Browser Directories ticked) access level to the Site Collection and all subsites are inheriting from their parent site.

Any ideas? Or how I could debug this further?

Many thanks in adv
Shennu
Coordinator
Dec 5, 2013 at 5:36 PM
Shennu:

Sounds like you're passing in some bad parameter(s). Can you post your code?

M.
Dec 6, 2013 at 8:41 AM
sympmarc wrote:
Shennu:

Sounds like you're passing in some bad parameter(s). Can you post your code?

M.
Hey Sympmarc, thanks for getting back.

here is the code, it is called from a CEWP on the home page the site collection. When I login it runs fine, but if I login as a site member with contribute permission it failes. See errors as comments in the code please.
$().SPServices({
  operation: "GetAllSubWebCollection",
  webURL: "/",
  async: false, 
  completefunc: function(xData, Status) {
  alert("Status=" + Status); //on this line it returns ParseError 
        var out = $().SPServices.SPDebugXMLHttpResult({
            node: xData.responseXML //xData.responseXML is undefined.
        });
        $("#CEWP_ServicesSummary").html("<b>This is the output from the GetAllSubWebCollection operation:</b>" + out);
  }
});
I couldn't work out why it fails, so I am using GetWebCollection and call it recursively in order to walk through the all the sub webs. That seems to work with the same site member... The only worry is the performance... What do you think?

Cheers
Shennu
Coordinator
Dec 6, 2013 at 2:34 PM
Shennu:

Performance definitely will be less if you take the GetWebCollection route, but it'll work. If you look at the network traffic you should be able to see more detail on what the parseError is.

M.
Dec 6, 2013 at 3:40 PM
sympmarc wrote:
Shennu:

Performance definitely will be less if you take the GetWebCollection route, but it'll work. If you look at the network traffic you should be able to see more detail on what the parseError is.

M.
Hey Sympmarc,

By network traffic, do you mean to look into the header info of the packets?

Shennu
Coordinator
Dec 6, 2013 at 3:59 PM
Use Firebug or Fiddler to look at the entire packet contents. The Status value just tells you whether the SOAP call occurred or not, not anything about what the error in the packets might be.

M.
Dec 6, 2013 at 4:48 PM
Will do. Cheers
Dec 7, 2013 at 12:43 PM
If the 'status' param to completefunc() is the one that has 'error' on it, then I don't think traffic is actually even being generated. That normally tells me you have invalid XML and the browser is choking on it.
You may have to use the browser dev tools to debug further.

/Paul


--

_________
Paul T