siteMapNodeVisibilityProvider not working?!

Oct 22, 2011 at 4:09 PM

Hi everybody,

my requirement is to hide/show some nodes in the menu of the application. I thought doing this using the visibilityProvider.

The  following is a stripped down version of my sitemap

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index">  
    <mvcSiteMapNode title="Front" controller="Public" action="Front"/>
    <mvcSiteMapNode title="About us" controller="Public" action="AboutUs"/>
    <mvcSiteMapNode title="Login" controller="Public" action="Login"/>

    <!-- This is the administration part -->
    <mvcSiteMapNode title="Admin" controller="Admin" action="Index" visibilityProvider="MyProject.Web.Providers.LoggedOnVisibilityProvider">
      <mvcSiteMapNode title="Frontpage" controller="Admin" action="Front"/>
      <mvcSiteMapNode title="AboutUsPage" controller="Admin" action="AboutUs"/>
    </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMap>

The  LoggedOnVisibilityProvider is as follows:

 

public class LoggedOnVisibilityProvider : ISiteMapNodeVisibilityProvider
    {
        public bool IsVisible(SiteMapNode node, HttpContext context, IDictionary<string, object> sourceMetadata)
        {
            bool retValue = (bool)context.Session[Globals.Global.CURRENT_USER_IS_ADMIN];         
            return retValue;            
        }
    }

In web.config:

<siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
      <providers>
        <clear />
        <add name="MvcSiteMapProvider"
             type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
             siteMapFile="~/Mvc.Sitemap"
             securityTrimmingEnabled="true"
             cacheDuration="5"
             enableLocalization="true"
             scanAssembliesForSiteMapNodes="true"
             excludeAssembliesForScan=""
             includeAssembliesForScan=""
             attributesToIgnore="bling,visibility"
             nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
             controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
             actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
             aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
             siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider"             
             siteMapNodeVisibilityProvider="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider"
             siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider"
         />        
      </providers>
    </siteMap>

 

It seems  not work! 

Currently i'm using ver 3.1. 
Thanks in advance 

 

Oct 25, 2011 at 6:17 PM

It appears to be broken for me as well.

Coordinator
Nov 22, 2011 at 7:44 AM

Does it hit the VisibilityProvider code when debugging? Because if I look at the config the siteMapNodeVisibilityProvider="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider" should probably be siteMapNodeVisibilityProvider="Your.Namespace.LoggedOnVisibilityProvider"