Hi all,
I need to security trim a list of sub sites retrieved via REST and jQuery. SharePoint's REST API is very inconsistent regarding security trimming, so I wanted to use a Security Trimmed Snippet. For a user with access to all sub sites it displays, but it gives me an "internal error" for a user who does not have access to 1 of the 10 sub sites that are outputted. Please help. This is what I have in the Script Editor Web Part currently. My goal is to have a security trimmed list of Sub sites.
<div data-name="SecurityTrimmedAuthenticated"><!--CS: Start Security Trim Snippet--><!--SPM:<%@Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>--><!--MS:<SharePoint:SPSecurityTrimmedControl runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ViewPages">--><!--PS: Start of READ-ONLY PREVIEW (do not modify)--><span><!--PE: End of READ-ONLY PREVIEW--><div class="DefaultContentBlock" style="border:medium black solid; background:yellow; color:black; margin:20px; padding:10px;"><script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script><script type="text/javascript"> $(document).ready(function ($) { var basePath = "https://yourcompany.com/sites/projects/_api/"; $.ajax({ url: basePath + "web/webs/?$select=*", type: "GET", headers: { "Accept": "application/json;odata=verbose" }, success: function (data) { //script to build UI HERE $.each(data.d.results,function(index,value){ $("#SiteList").append("<p>" + "<a href='" + value.Url + "'>" + value.Title + "</a></p>"); }); }, error: function (data) { //output error HERE alert(data.statusText); } }); });</script><div id="SiteList"><h2>Projects List</h2></div></div><!--PS: Start of READ-ONLY PREVIEW (do not modify)--></span><!--PE: End of READ-ONLY PREVIEW--><!--ME:</SharePoint:SPSecurityTrimmedControl>--><!--CE: End Security Trim Snippet--></div>
Personal Blog: http://thebitsthatbyte.com