Dynamic Menu Control in ASP.NET2

S

Sri Reddy

Hi
I want to create a horizontal menu on my website being built using
asp.net2 with menu items based on the "role" of the user who logged into
the system.Role iformation will be read from database...

For ex:
for a user with "Admin" role, i would like to show "Menu Item1", "Menu
Item2", "Menu Item3", "Menu Item4". Where as if the user belongs to
"Help-desk" role, i would like to show only "Menu Item1" and "Menu
Item3"...

Also, i want to provide an alternative to access "Menu Items" if the
java-script is disabled...

Wondering what options do i got....
Thanks
Sri
 
K

Kelly Leahy

I don't know about the non-javascript support - you'd probably have to do
something with a vertical menu for that - horizontal ones get a bit unwieldy
when they have to be static.

As for doing the horizontal dynamic menu, the way I did it was with a
SiteMap file and setting role-based access to folders under the site (Admin
folder, Members folder, etc.). Then, you can turn on role-checking in the
web.config file. Alternatively (and a bit faster) you can use the roles
attribute in the entries in the sitemap (see help on site maps for the
syntax).

My menu looks like:
<asp:Menu ID="Menu1" runat="server" BackColor="#AFBFFF"
DynamicHorizontalOffset="2"
DataSourceID="SiteMapDS"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#666666"
ItemWrap="True" Orientation="Horizontal" StaticSubMenuIndent="10px">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#666666" ForeColor="White" />
<DynamicMenuStyle BackColor="#AFBFFF" BorderColor="#D1DDF1"
BorderStyle="Solid" BorderWidth="1px"/>
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#666666" ForeColor="White" />
</asp:Menu>
<asp:SiteMapDataSource runat="server" ID="SiteMapDS"
ShowStartingNode="false" />

not sure if all the <StaticXXX> tags are needed - they are there for
historical reasons on my site ;)

In my web.config, I have:
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<clear/>
<add name="XmlSiteMapProvider"
description="Default SiteMap provider."
type="System.Web.XmlSiteMapProvider "
siteMapFile="Web.sitemap"
securityTrimmingEnabled="true" />
</providers>
</siteMap>

Cheers,
Kelly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top