asp.netasp.net-mvc-3web-configsitemapprovidersecurity-trimming

How to use Custom SiteMapProvider in ASP NET MVC?


I am currently trying to implement a Custom SiteMap Provider. I have read several tutorials about it, and followed their lead.

I have created a subclass of XmlSiteMapProvider named MySiteMapProvider which is located in MyProject.Security.

I have added the following code to the system.web section of my Web.config:

 <siteMap defaultProvider="MySiteMapProvider" enabled="true">
        <providers>
            <add name="MySiteMapProvider"
              description="Custom SiteMap provider."
              type="MyProject.Security.MySiteMapProvider "
              siteMapFile="Web.sitemap"
              securityTrimmingEnabled="true" />
        </providers>
    </siteMap>

But I am sure that my Provider is not used correctly. I couldn't even start with the implementation. To verify that I have included the following (pseudo) implementation:

 public override bool IsAccessibleToUser(System.Web.HttpContext context, System.Web.SiteMapNode node)
    {
        Debug.Print("Hello World");
        throw new Exception();            
        return base.IsAccessibleToUser(context, node);
    }
    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection attributes)
    {
        Debug.Print("Hello World");
        throw new Exception();     
        base.Initialize(name, attributes);
    }
    public override SiteMapNode BuildSiteMap()
    {
        Debug.Print("Hello World");
        throw new Exception();     
        return base.BuildSiteMap();
    }

But I can use the site and navigate as much as I want to, no Exception comes up and the Debug console shows no Hello World at all.

Did I forget something important?


Solution

  • Instead of implementing my own Provider, I went along with the MvcSiteMapProvider. The customization of the behaviour that I needed to implement was realized in one day with dynamic sitemaps and a custom SiteMapNodeVisibilityProvider.

    I also considered implementing the whole SiteMapProvider, maybe on SQL basis, and I am glad that I did not have to do it.