I'll try to put my problem as simply as possible below. Excuse me of etiquette mishaps and such as I'm totally new here and have been working with SharePoint only for a few months. Be sure to correct me though.

I'm building a custom navigation with SharePoint 2013. I'm at a point where I have a working Metadata Navigation in place. I need a way to go through the terms in the Site Navigation term set so that I can spit out a custom (html) menu structure to certain publishing page layouts.

I've read lots of forums, posts and articles but can't really decide what would be the right way to go with this. Some say it should be done with client side JavaScript but for me it feels like a wrong way to implement such a critical part of the site.

I've also read that using code behind in page layouts (.aspx) isn't the best way to go as it might lead to security problems. I feel like I'm left with nothing.

At the moment this forums seems the only place I could find pro-level people who could guide me to the right direction. Every answer and every intention to help is greatly appreciated!

The problem more specifically and in a form of a question:

I need to display a three levels deep Metadata based navigation (with friendly urls) in a page layout. Each of the navigation levels must be shown in different places in the page with a different set of styles. How can I achieve this?

Below is a link to a picture to illustrate what I mean.

enter image description here

2 Answers 2


If you want to show the navigation to Anonymous users too, then using the Server Side Object Model is your only option. You can run the navigation code inside a code block with elevated privileges. Also, modifying the navigation with the Server Object Model is only allowed in Farm Solutions. See this link for examples:


  • Ok, thank you for answering! This is good to know. This means I can ditch the JavaScript way and focus on the server side. Where should I implement the C# code that fetches the navigation items from the Site Navigation term set? If I've understood correctly it's not a straight forward thing to use code behinds with page layout (.aspx) files with SharePoint and I don't know where to execute the code if not in the page layout code behind.
    – sarukuku
    Jul 16, 2013 at 9:49
  • Why do you think its not safe to execute c# code in code behinds of pages? I have implemented solutions like that without any problems in the past. Jul 16, 2013 at 9:56
  • I think I've just read about security problems somewhere and you're probably right. I just don't know how to get the page layout pages code behinds work with SharePoint. I tried them but the pages always exploded with a server error that the class it inherited could not be found. Then I read a few tutorials that told SharePoint won't allow code run from the code behind files on the aspx pages without touching the web.config or doing some other weird tricks. Inline code is also a no go as it would not work anymore after users edit the page and it get's stored to the database.
    – sarukuku
    Jul 16, 2013 at 10:03
  • I guess we are now deviating from the main question. You can post another question if you are having trouble working with ASPX pages and someone might help you on that. Jul 16, 2013 at 10:36

This isn't a question however it is something that may want to become a source of information.

Could you reformat your post as a question so it complys with the rules of stackexchange?

Have you considered using the out of the box navigation and formatting it with JavaScript?

To help guide you here are some directions you can look at to reformat this as a compliant question.

Global navigation:


Modifying Navigation with JavaScript


Styling navigation snippets


  • Sure! I'll try to make it more specific and more question-like.
    – sarukuku
    Jul 15, 2013 at 13:03
  • And to let you know I've tried the js way but I couldn't get it working with anonymous authentication. The problem with the out of the box navigation is that it always displays all levels of the navigation. I need to be able to show different levels of navigation in different places on the page.
    – sarukuku
    Jul 15, 2013 at 13:06

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.