PDA

View Full Version : Navigation


kasl
07-19-2006, 07:09 AM
Looking to control how the navigation bar (menu) is controlled.

I understand how the sitemap file contains the menu items, but how do you control what menu items are displayed if you are logged in?

If you log in you see a menu and if your not logged in you see a differenct menu.

Any help pointing me in the right direction is greatly appreciated.

Scott

Aristotle
07-19-2006, 10:15 AM
Taking the Personal Web Starter Kit as an example, the way it's done is through the securityTrimmingEnabled property of the siteMap provider.

Part of the web.config looks like this:

[quote]
<siteMapdefaultProvider='XmlSiteMapProvider'enabled ='true'>
<providers>
<addname='XmlSiteMapProvider'
description='SiteMapproviderwhichreadsin.sitemapXM Lfiles.'
type='System.Web.XmlSiteMapProvider,System.Web,Ver sion=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f 7f11d50a3a'
siteMapFile='web.sitemap'
securityTrimmingEnabled='true'/>
</providers>
</siteMap>
...
...
...
<locationpath='Admin'>
<system.web>
<authorization>
<allowroles='Administrators'/>
<denyusers='*'/>
</authorization>
</system.web>
</location>
</CODE>

The web.sitemap looks like this:

[quote]

<siteMap>
<siteMapNodetitle='Home'url='Default.aspx'>
<siteMapNodetitle='Resume'url='Resume.aspx'/>
<siteMapNodetitle='Links'url='Links.aspx'/>
<siteMapNodetitle='Albums'url='Albums.aspx'>
<siteMapNodetitle='Photos'url='Photos.aspx'>
<siteMapNodetitle='Details'url='Details.aspx'/>
</siteMapNode>
</siteMapNode>
<siteMapNodetitle='Register'url='Register.aspx'/>
<siteMapNodetitle='Manage'url='Admin/Albums.aspx'>
<siteMapNodetitle='Photos'url='Admin/Photos.aspx'>
<siteMapNodetitle='Details'url='Admin/Details.aspx'/>
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
</CODE>

The sitemap provider will do a role check on the nodes of the sitemap, which determines what to display or not display to the user. Since only the Administrators have access to the Admin directory, the nodes which have Admin path in the url will only be displayed to Administrators.

Aristotle

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

Post Edited (Aristotle [DASP]) : 7/19/2006 11:24:45 PM GMT

kasl
07-20-2006, 01:08 AM
Thanks Aristotle..

Setting the securityTrimmingEnabled='false' now shows all nodes in the Sitemap.

One problem though.. I would still like to control what menu items appear based on who is logged in.

I'm still now sure how or what controls how the menu appears.
All my pages are in the root and my sitemap looks similar to your example.

Thanks again....

Aristotle
07-20-2006, 02:31 AM
Going with the same example I had earlier, the location element in the web.config is used to set the permissions for the particular sections of the site.

You can add additional location elements. For example, to allow the Albums.aspx page to only be seen by your friends (assuming you have created a role called Friends), then add this in the web.config:

[quote]
<locationpath='Albums.aspx'>
<system.web>
<authorization>
<allowroles='Friends'/>
<denyusers='*'/>
</authorization>
</system.web>
</location>
</CODE>

Aristotle

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)