asp:menu control and SiteMap, 'Selected' Item must match exact url?
So I am back into making .NET websites... and I love the web.sitemap feature of .NET 2.0+ However, I like my web folder structure to be semantic. This means that instead of clunky files with extensions, I like to have a directory for every portion of the site. Example:
http://www.website.com/products/, http://www.website.com/aboutus/
And then every folder has a Default.aspx ... but the problem with this is that the sitemap, when connected to an ASP.NET Menu control, is that the selected page is only recognized if the page name is included... so my sitemap has to be /products/Default.aspx , instead of just /products/... that's a bummer, because then I lose my semantic 'feel'.
Anyone have any ideas on how to modify this? I'd prefer not to override the Menu control if I don't have to.
Update: So I dug a little deeper and found a solution. First, in your web.sitemap file, keep all the URLs to be exact, including the Default.aspx file. Then, in your menu control, add an onDataBound event handler as such:
protected void SubMenu_DataBound(object sender, EventArgs e)
{
foreach (MenuItem Mi in ((Menu)sender).Items)
{
//Trim default.aspx from Menu Item URL; this is for SEO
Mi.NavigateUrl = Mi.NavigateUrl.Replace("Default.aspx", "");
}
}