Home All Groups Group Topic Archive Search About

Dynamic Menu Control in ASP.NET2

Author
2 May 2006 4:30 PM
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



*** Sent via Developersdex http://www.developersdex.com ***

Author
2 May 2006 6:12 PM
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

Show quoteHide quote
"Sri Reddy" wrote:

>
>
>
> 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
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>