I know i been away but here is part three, this version checks your Asp_net role and the roles for a current node. Veri simple but the menu looks very cool

[Serializable()]
public class CssMenu : Panel
{
private SiteMapDataSource xds;
private string[] userRoles;

private bool HasRoles(SiteMapNode item)
{

bool retval = false;
foreach (string item2 in item.Roles)
{
if (item2.ToString().Equals("*"))
retval = true;
foreach (string item1 in userRoles)
{
if (item1.Equals(item2.ToString()))
retval = true;
}
}
return retval;
}

public SiteMapDataSource DataSource
{
get
{
return xds;
}

set
{
xds = value;
}
}
///
///
///
public string CssId
{
get
{
if (ViewState["CssId"] == null)
ViewState["CssId"] = "";
return (string)ViewState["CssId"];
}
set
{
ViewState["CssId"] = value;
}
}
///
///
///
public bool StartAtRoot
{
get
{
if (ViewState["StartAtRoot"] == null)
return false;
return (bool)ViewState["StartAtRoot"];
}
set
{
ViewState["StartAtRoot"] = value;
}
}
///
///
///
public string CssCurrentClass
{
get
{
if (ViewState["CssCurrentClass"] == null)
ViewState["CssCurrentClass"] = "";

return (string)ViewState["CssCurrentClass"];
}
set
{
ViewState["CssCurrentClass"] = value;
}
}
///
///
///
public int ChildLevels
{
get
{
if (ViewState["ChildLevels"] == null)
ViewState["ChildLevels"] = 1;

return (int)ViewState["ChildLevels"];
}
set
{
ViewState["ChildLevels"] = value;
}
}
///
///
///
private void LoaChildsNodes(SiteMapNodeCollection smnc, ref Panel obj)
{
Literal lit = new Literal();
lit.Text = " ";
      obj.Controls.Add(lit);
      foreach (SiteMapNode item in smnc)
      {
      //if (this.HasRoles(item.Roles))
      // {
      lit = new Literal();
      lit.Text = "* ";
      obj.Controls.Add(lit);
      HyperLink lnk = new HyperLink();
      lnk.Text = item.Title;
      lnk.NavigateUrl = item.Url;
      if (Page.Request.RawUrl.ToLower().Contains(item.Url.ToLower()) && (CssCurrentClass.Length > 0))
      lnk.CssClass = CssCurrentClass;
      else
      lnk.CssClass = "";
      obj.Controls.Add(lnk);
      lit = new Literal();
      lit.Text = "  ";
      obj.Controls.Add(lit);
      // }

      }
      lit = new Literal();
      lit.Text = "";
obj.Controls.Add(lit);
}
protected override void OnDataBinding(EventArgs e)
{
base.Controls.Clear();
base.OnDataBinding(e);
SiteMapNodeCollection smnc;
userRoles = Roles.GetRolesForUser();
xds = this.DataSource;
if (StartAtRoot)
smnc = xds.Provider.GetChildNodes(xds.Provider.RootNode);
else
smnc = xds.Provider.GetChildNodes(xds.Provider.CurrentNode);

Literal lit = new Literal();
lit.Text = "";
      base.Controls.Add(lit);

      foreach (SiteMapNode item in smnc)
      {
      if (HasRoles(item))
      {
      lit = new Literal();
      lit.Text = " * ";
      base.Controls.Add(lit);
      HyperLink lnk = new HyperLink();
      lnk.Text = item.Title;
      lnk.NavigateUrl = item.Url;
      if (Page.Request.RawUrl.ToLower().Contains(item.Url.ToLower()) && (CssCurrentClass.Length > 0))
      {
      lnk.CssClass = CssCurrentClass;
      }
      else
      {
      lnk.CssClass = "";
      }
      base.Controls.Add(lnk);
      SiteMapNodeCollection smc2 = xds.Provider.GetChildNodes(item);
      if ((this.ChildLevels > 1) && (smc2.Count > 0))
      {

      Panel pn = new Panel();
      lit = new Literal();
      lit.Text = "";
      pn.Controls.Add(lit);
      this.LoaChildsNodes(xds.Provider.GetChildNodes(item), ref pn);
      lit = new Literal();
      lit.Text = "";
      pn.Controls.Add(lit);
      base.Controls.Add(pn);
      }
      lit = new Literal();
      lit.Text = "";
      base.Controls.Add(lit);
      }
      }
      lit = new Literal();
      lit.Text = "";
base.Controls.Add(lit);

}

}

I didn’t post any css in my previous post for the use of the menu control this is the css i used when i was creating it. The Menu Id is a horizontal menu and Nav Id is a vertical menu, as you can see all i have to do is assign the CssId to the control and we manage the look with css and the content in code.

My next post will be about using the Roles to determine access to the user.

Sample CSS:

/**** Main Menu ***/

#menu {
display: block;
float:right;
}

#menu ul {
margin: 0;
list-style: none;
}

#menu li {
display: block;
float: left;
white-space: nowrap;
}

#menu li a {
display: block;
padding: 55px 20px 12px 20px;
text-decoration: none;
color: #fff;
font-weight: bold;
}

* html #menu a {width:1%;}

#menu li a:hover {
background: url(../img/bg_menu.gif);
}

#menu li a.current {
letter-spacing: 1px;
color: gray;
background: url(../img/bg_menu.gif);
}

#menu li a.current:hover {
color: #fff;
}


/**** nav ***/
#nav{ list-style: none; margin: 2.0em 0; width: 25em; float: right;}
#nav li{ padding: 0; margin: 0; }
#nav a{
display: block;
height: 2.0em;
padding: 0.3em 0.3em 0.3em 0.8em;
border-bottom: 2px; /*solid #1a1a1a*/
border-top: 2px; /*solid #1a1a1a*/
color: #93B300;
background-color: #F7F9FB;
font-weight: bold;
text-decoration: none;
}

#nav a:hover{
color: #1a1a1a;
background: url(../img/bg_t.gif) no-repeat;
background-color: #fff;
font-weight: bold;
}