Dynamic menu, multiple sitemapprovider, etc.
Everyone has been shouting "three cheers!" and "horray" since the arrival of .NET thing. How could I go against the tide?
Still. Still feel that ASP .NET comes with packages, impressive yet unwieldy. For each problem, it hands out one heavy-set, all inclusive solution. The key is how to dig into the solution kit and fish out the right method, member and clear ways to manipulate... Very often, that means encyclopedia-like knowledge or extensive search.
That is what happened today at my work (still busy as hell!).
Problem 1: I needed to implement role-based dynamic memu, so different people get to see different things. I thought it would be a piece of cake.
Go search.
I found 3 possible ways to implement.
a) Create multiple Sitemap files. Specify it in the web.config file. Then dynamically switch the sitemapdatasource to the right SiteMapProviders.
Sample web.config:
<siteMap defaultProvider="FLSA_SiteMapProvider" enabled="true" ><providers>
<
add name="DefaultSiteMapProvider"
description="Default SiteMap provider."
type="System.Web.XmlSiteMapProvider "siteMapFile="Web.sitemap" />
<
add name="AdminSiteMapProvider"
type="System.Web.XmlSiteMapProvider"siteMapFile="~/admin.sitemap" />
<
add name="AuthorizedUserSiteMapProvider"
type="System.Web.XmlSiteMapProvider"siteMapFile="AuthorizedUser.sitemap" />
</
providers>
Sample Master file:
....
in the page_load function:
if (Request.IsAuthenticated)
{
if (uname == "admin")
SiteMapDataSource1.SiteMapProvider =
"AdminSiteMapProvider";
elseSiteMapDataSource1.SiteMapProvider = "AuthorizedUserSiteMapProvider";
}
elseSiteMapDataSource1.SiteMapProvider = "DefaultSiteMapProvider";
Solution 2:
Use multiple place holders for different menus, dynamically set the visibility of the menus.
Solution 3:
Programmically add/or remove menu nodes.
...
Problem 2: My sitemap needs have to some section headers with empty links. I thought that would be a given too. Turned out there is no easy and elegant solution. So far I am still searching.
Wonder if anyone would be so kind to show me the way.