Read Context.Web.Navigation.QuickLaunch with Audeince - Sharepoint Publishing Site

I am trying to recreate my master page in my Provider Hosted App. To do this I need to recreate the quick Launch bar. I have sucessfully recreated it, However I can not see a way to security trim it to the audience. In SharePoint, I just goto Settigns -Navigation and then Add the Audience I want to view the link, However I cant see how I can trim it in C#.

So far I have:

      

NavigationNodeCollection topNav = clientContext.Web.Navigation.QuickLaunch;
clientContext.Load(topNav);
clientContext.ExecuteQuery();                        
foreach (var nav in topNav)                        
{                                                          
clientContext.Load(nav.Children);                        
}                        
clientContext.ExecuteQuery();                        

return topNav;

THis code returns a NavigationNodeCollection but no way for me to trim it against the audience in Navigation

March 17th, 2015 12:33am

Hi,

Usually Security Trimming is done by SharePoint system for the user you are running under - so if you are running under the user that will see the result all should be fine.

In your case, since you have a provider hosted app, the access to the SharePoint site is done using one account.

You need to implement the security trimming yourself

- you can set the Audience in the same place

- read it using something like this:

     navigationNode.Properties["Audience"] 

After that you need to decide if you display that node or not for the current user or not.

Cheers,

Dan.


Free Windows Admin Tool Kit Click here and download it now
March 17th, 2015 11:10am

Hi,

In Server side, we can use SPNavigationNode.Properties["Audience"] to set audience.

https://arunjameskc.wordpress.com/2012/12/16/programmatically-set-audience-targeting-sharepoint-audience-to-left-navigation-node/

We can't find the Client API to achieve the same function. You can see the NavigationNode members.

https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.client.navigationnode_members.aspx

As a workaround, we can custom a Web Service and use Server Object Model to Achieve it, then Call the service from your Provider Hosted App.

How to create Custom Web Service WCF (REST) in SharePoint 2013

http://www.codeproject.com/Articles/764102/How-to-create-Custom-Web-Service-WCF-REST-in-Share

Using REST Services with a Provider Hosted App in SharePoint 2013

https://samlman.wordpress.com/2015/03/02/using-rest-services-with-a-provider-hosted-app-in-sharepoint-2013/

Best Regards

March 19th, 2015 2:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics