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">
     <providers>
         <add name="LSXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             siteMapFile="web.sitemap" securityTrimmingEnabled="true" />
    </providers>
siteMap>

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>
        <siteMapNode title="$resources:Strings, NavigationHelp" roles="*">
            <siteMapNode url="~/About.aspx" title="$resources:Strings, NavigationAboutPage" />
            ...
        siteMapNode>
    </siteMapNode>
</siteMap>

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.

Advertisements