Wednesday, June 2, 2010

How to create a security trimmed top link in a WSS 3.0 site

Introduction

The other day I had this issue with an out of the box WSS 3.0 site. I had created some subsites. While creating the subsite, one of the options is to choose ‘Display this site on the top link bar of the parent site?’ You can either choose Yes or No.

image

Choosing Yes will of course show the link to this subsite, choosing No will not show the link. Incidentally I choose No in one of my subsites, thus the subsite is not showing in the top link bar of the parent WSS site. It does show in the quick launch bar.

image

Within WSS 3.0 you have the option through Site Actions, Site Settings, in the Look and Feel column to go to the Top link bar and create your own custom ‘tabs’. I created the subsite3 tab and it did show now on the top link bar. Issue closed, me:1 SharePoint: 0…… Not!!!!!

Security trimmed navigation

Here is where security comes into play. When you create a subsite, automatically SharePoint makes it a security trimmed ‘tab’ or link. Meaning, if you have permissions on this subsite, you’ll see the tab. If not, the tab will not show. Nothing new under the sun is it? Just plain good old SharePoint. However, the tab ‘subsite3’ I just created is NOT, I repeat, NOT security trimmed. BTW, if you had chosen Yes and let the link be displayed on the top link bar and then deleted the link and re-created it, it also would not be security trimmed.

I’ll show you how you can see this in the Top link bar and in a real time scenario.

Through Site Actions, Site Settings, in the Look and Feel column go to the Top link bar. Click on the edit button before ‘subsite1’. Notice that the url is greyed out?

image

Now go back 1 step and click on the edit button before ‘subsite3’. Notice that the url is NOT greyed out?

image

Real time scenario

In subsite 1 and 3 I broke the inheritance with the top level Demo site collection and created unique permissions. My demo user ‘Marc Manager’ does NOT have permissions to these subsites. Marc Manager has only got permissions on the top level Demo site collection and Subsite 2.

image

Now, when I log on with the credentials of Marc Manager, you will see that the ‘Subsite3’ tab is NOT security trimmed. The ‘subsite1’ tab is not show, the subsite3 tab does show because it’s just a link. Notice that in the quick launch the ‘subsite3’ link has dissapeared. This is because when I created the subsite 3 website, I choose the option ‘Display this site on the quick launch of the parent site, YES’, thus making it a security trimmed link.

image

So obviously, Marc Manager – the guy he is -  sees the subsite 3 link. When he clicks on it, he will get the logical error, and blaming the whole world and IT Pro’s for this not so friendly error message…..

image

the big questions is.. How can we solve this?

The solution

Okay, ready to dive into some SharePoint Designer? Open up Sharepoint Designer and open the Demo top level site collection website. Always wondered what this Navigation link was?

image

You can also go in the Menu Bar to Site, and choose Navigation from the pull down menu.

You will get this nice Visio kinda’ tree view of the Demo website. This is called the Navigation Map.

image

Within SharePoint Designer, in the Navigation Map you can also build you own top link bar links and quick launch links.  Now right-click on the most right Tab ‘The SharePoint Tob Navigation Bar’ and choose ‘View subtree only’. You will see something like this:image

The Sharepoint Top Navigation Bar has 4 nodes under it. One is Home, which point to the Home page of the Top level site and the others are Subsite1, subsite2 and subsite3.

Now right-click the Sharepoint Top Navigation Bar node and click New -> Page. It will add a node under the Sharepoint Top Navigation Bar. Double click it (this is very important that you do this), it will create a untitled htm page (which you can close immediately) and then back on the untitled 1, right-click it. Choose Properties. You will see something like this:

image

It will allow you to Edit the Hyperlink. If you scroll down, you will see that the Subsite3 site is listed and you could dubbel click it and then select the ‘default.aspx’  and click OK. After this, click once on the untitled 1.html and it will change into the newly created hyperlink. The new added node will point to the Subsite3 now. BTW, the title now shows Subsite3/default.aspx. You can change the title into ‘Subsite 3 security trimmed’ by clicking once on this title. The end results shows something like this:

image

Save the site and then close Sharepoint Designer. Go back to the WSS Demo site, log into this site with administrator credentials and you will find the Subsite3 security trimmed tab is listed in the Top Link Bar.

image

Just checking. Again, go to Site Actions, Site Settings, in the Look and Feel column go to the Top link bar.  Click on the edit button before ‘subsite3 security trimmed’. Notice that the url is greyed out?

image

Almost there. Now go to the edit button before ‘subsite3’ and choose Delete.

Finally, go back to the WSS top level site collection Demo and again login with Marc Managers’ credentials. Marc will now only see the sites he’s got permissions on through the security trimmed top link bar.

image

Marc Manager is now a happy SharePoint demo user again….