Display XML Menu Items Based On User
page 4 of 7
by Andrew Mooney
Average Rating: 
Views (Total / Last 10 Days): 34055/ 33

Site Map

While the site map XML file can be stored anywhere, I recommend placing it in the App_Data folder. This is the XML file that we will use to store the links for the menu control. This example uses a two level menu. You could add more levels, but you will also need to edit the menu control data bindings in master page. In Listing 5 the XML site map has two levels group and page. Typically, you would use one group for each restricted sub directory and one page for each page in that directory. The group node is the top level of the drop down menu and has a link that you could use for the default page in each directory. However, you can use this link for any URI. You could also have a group with pages that contain all external links. One important thing to note here is that the group user property should be set the same as the users that are allowed in the web.config for the group directory.

The user property of the group node controls whether or not the entire group is displayed for the current user. You can also use the word "none" to allow anonymous users to view a certain menu group and the web.config file in the sub directory allows access to the pages in it. Normally, these users would be the same. You can also use external links which do not require directory access, but can still be displayed only to certain users by setting the group user property in the site map XML file.

The title property of both the group and page nodes is the text that will be displayed in the menu. Of course, the URL property contains the URL for the menu item. Create a sub directory named App_Data and place the SiteMap.xml file in it.

Listing 5 - This is the SiteMap.xml

<?xml version="1.0" encoding="utf-8" ?>
  <group title="Home" url="~/Default.aspx" users="none,user1,user2">
    <page text="Log In" url="~/Login.aspx"/>
  <group title="Weather" url="" users="none,user1,user2">
    <page text="Weather Channel" url="http://weather.com"/>
    <page text="MSN Weather" url="http://weather.msn.com"/>
  <group title="MSN TV" url="http://tv.msn.com" users="user1">
    <page text="Yahoo TV" url="http://tv.yahoo.com"/>
  <group title="Restricted Area" url="~/Restricted/Default.aspx" users="user2">
    <page text="MSDN" url="http://msdn.microsoft.com"/>
    <page text="ASP.NET" url="http://microsoft.com"/>
    <page text="ASPAlliance" url="http://aspalliance.com"/>

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 4:22:30 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search