We run a site that uses master pages and creates its navigation using the built-in ASP.NET sitemap provider. The navigation presents itself as a CSS rollover menu. Our client would like to show the entire menu, including 2 levels of sub-menus, to one audience while restricting a different audience to a single level of navigation. My code knows the audience based on a cookie value.
Rather than duplicate the user control or master page, I would like to add a parameter to the user control that would show or hide the lower levels of navigation.
How should I implement this to maximize performance? The article below explained some of the concepts, but I would like to hear from people who have done this in production.
Caching Multiple Versions of a User Control by Using Declarative Attributes http://msdn.microsoft.com/en-us/library/53a3xxk8%28v=VS.71%29.aspx
Here's the code.
private void GetNodes(XmlNode node, int intDesiredDepth, int intNodeDepth, StringBuilder sb)
{
if (node is XmlElement)
{
intNodeDepth++;
string strFirstUL = "";
if (intNodeDepth == 1)
{
strFirstUL = " id='nav'";
}
if (intNodeDepth <= intDesiredDepth)
{
if (node.Attributes.Count > 0)
{
GetAttributes(node, sb, intDesiredDepth);
}
if (node.HasChildNodes & intNodeDepth < intDesiredDepth)
{
sb.Append("<ul" + strFirstUL + ">");
foreach (XmlNode child in node.ChildNodes)
{
GetNodes(child, intDesiredDepth, intNodeDepth, sb);
}
sb.Append("</ul></li>");
}
}
}
ltlNav.Text = sb.ToString();
return;
}