Tag: sitemap

ASP.NET Menu control with Web.sitemap datasource

I’ve added an ASP.NET Menu control to a website and use a SiteMapDataSource control as the data source for the Menu control. The SiteMapDataSource control uses the XmlSiteMapProvider, directly linking it to the Web.sitemap file. Now, I’m using the Menu control to easily manage security trimming, but I also have drop down menus, where the parent menu item shouldn’t link to anything, i.e. the url property/attribute should be omitted or have a blank value. If I do either, the parent menu item and the child menu items are not rendered. However, after enabling security trimming in the web.config file,

<siteMap defaultProvider="LSXmlSiteMapProvider" enabled="true">
         <add name="LSXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             siteMapFile="web.sitemap" securityTrimmingEnabled="true" />

and added the roles attribute with a value of all (*), I could omit the url property as show here:

xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" enableLocalization="true">
    <siteMapNode url="~/" title="$resources:Strings, NavigationHomePage">
        <siteMapNode title="$resources:Strings, NavigationTables" roles="*">
            <siteMapNode url="~/Shops/ListDetails.aspx" title="$resources:Strings, NavigationShopsPage" />
        <siteMapNode title="$resources:Strings, NavigationHelp" roles="*">
            <siteMapNode url="~/About.aspx" title="$resources:Strings, NavigationAboutPage" />

Now, localization has also been enabled, but as you can see from the NavigationTables” roles=”*”> and NavigationHelp” roles=”*”> xml elements, all users are allowed to see these menu items. They’re simple rendered as text only, no hyperlink.


Hide Pages from ASP.NET Menu control

When you use the Menu control with the SiteMapDataSource control and an associated XML sitemap file, and also use the SiteMapPath control for creating the bread crumb, you often need to include specific pages in the sitemap file, but hide the same pages from the menu. If you don’t include a page in the sitemap file, it isn’t shown in the menu, which is what you want, but when you then browse to that specific page, your breadcrumb disappears. The option is to include the page in the sitemap file, but add a custom attribute, like this, where we want to hide the SearchResults.aspx page from the menu. Notice that we’ve added the HideFromMenu attribute with a value of true.

xml version="1.0" encoding="utf-8" ?>

             url="~/SearchResults.aspx" />

Continue reading “Hide Pages from ASP.NET Menu control”