I had another frustrating experience today, but I learned a lot. Again, ASP is easy to use if you want to do it a certain way… it can be a bit of a pain to figure out how to do things another way.
Anyhow, the story was to implement a navigation menu, which intelligently only showed the appropriate menu items to users in particular roles. For example, only admins should see certain pages, such as create class and create new user.
The concept was pretty simple, but it wasn’t as easy as I expected. First, I had to create a sitemap XML file for the site, which tells ASP how the pages map out. I wanted a top-level menu with Home, My Account, and Admin menu items. It wouldn’t let me, because it needed a root node.
So I put a root above everything, but when I used the sitemap as a data source for an ASP menu (which shows a dynamic menu), it showed the Root as the top level. I didn’t want this to appear at all. After fighting awhile with ASP by removing the node, or by trying to see how the menu could start from the second level, I finally found the answer online, which was that when the datasource was configured for the sitemap, there is a “skip root node” option. It was a really simple fix, but it just took an excruciating amount of time to find.
Setting up the role-based visibility of menu items was a little harder to implement, but at least all the information on how to do it wasn’t too hard to find. Turns out you need to change things in three places — 2 different sections in the web.config file, and in the sitemap file.
Right now, I don’t have any Teacher-specific pages, so you can only see how the view is different between a student’s navigation menu:

And an admin’s navigation menu: (The greened menu signifies what page you are currently on.)

As always, excuse the ugliness until the UI revamp. It works, though.