Question

I would like to filter entries from web.sitemap using OnDataBinding event, but it does not execute. I would like to have functionality, which allows me to verify whether user's role have access to particular function.

I created table with list of functions and linking table to build priviledges. I am going to allow administrator to add new roles and give them set of functions which are allowed rather than using IsInRole which does not seem flexible enough to my needs.

So, I added the following:

<asp:sitemapdatasource ID="SiteMapMenuSrc" runat="server" ShowStartingNode="false" OnDataBinding="MainMenu_DataBinding" SiteMapProvider="SiteMap1"></asp:sitemapdatasource>

Where SiteMap is web.config entry:

<add name="SiteMap1" type="System.Web.XmlSiteMapProvider" siteMapFile="~/Web.sitemap"/>

It seems, that MainMenu_DataBinding is not called. I have not found any suitable explanation. What is wrong with my code?

Was it helpful?

Solution

That's because SiteMapDatasource is just a data source control it does nothing on its own

You actually have to use it, for example:

    <asp:Menu ID="Menu1" DataSourceID="SiteMapMenuSrc" runat="server" 
        Orientation="Horizontal" RenderingMode="Table" 
        StaticSubMenuIndent="16px">
        <StaticSelectedStyle Font-Bold="True" />
    </asp:Menu>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top