/// <summary> /// Determines whether the node is visible. /// </summary> /// <param name="node">The node.</param> /// <param name="sourceMetadata">The source metadata.</param> /// <returns> /// <c>true</c> if the specified node is visible; otherwise, <c>false</c>. /// </returns> /// <exception cref="System.ArgumentNullException">node</exception> public bool IsVisible(ISiteMapNode node, IDictionary <string, object> sourceMetadata) { if (node == null) { throw new ArgumentNullException("node"); } sessionStateProvider = new SessionStateProvider(); session = new SessionStateService(sessionStateProvider); //TODO: Uncomment below before deployment to prod. var isUserLoggedIn = (session.GetSessionValue(SessionKey.UserIsAuthenticated) ?? "").ToString().AsBoolean(); if (!isUserLoggedIn && (node.Title != "Home")) { return(false); } IRoleCollection roles = node.Roles; //if no role is associated to node - allow it to show if (!roles.Any()) { return(true); } var roleCollection = ((string[])session.GetSessionValue(SessionKey.UserRoles) ?? new[] { "" }).ToList(); var roleCollectionToUpper = roleCollection.Select(role => role.ToUpper()).ToList(); var isGranted = false; foreach (var role in roles) { isGranted = roleCollectionToUpper.Contains(role.ToUpper()); if (isGranted) { break; } } return(isGranted); }
public SiteMapNode( ISiteMap siteMap, string key, bool isDynamic, ISiteMapNodePluginProvider pluginProvider, IMvcContextFactory mvcContextFactory, ISiteMapNodeChildStateFactory siteMapNodeChildStateFactory, ILocalizationService localizationService, IUrlPath urlPath ) { if (siteMap == null) throw new ArgumentNullException("siteMap"); if (string.IsNullOrEmpty(key)) throw new ArgumentNullException("key"); if (pluginProvider == null) throw new ArgumentNullException("pluginProvider"); if (mvcContextFactory == null) throw new ArgumentNullException("mvcContextFactory"); if (siteMapNodeChildStateFactory == null) throw new ArgumentNullException("siteMapNodeChildStateFactory"); if (localizationService == null) throw new ArgumentNullException("localizationService"); if (urlPath == null) throw new ArgumentNullException("urlPath"); this.siteMap = siteMap; this.key = key; this.isDynamic = isDynamic; this.pluginProvider = pluginProvider; this.mvcContextFactory = mvcContextFactory; this.localizationService = localizationService; this.urlPath = urlPath; // Initialize child collections this.attributes = siteMapNodeChildStateFactory.CreateAttributeDictionary(key, "Attributes", siteMap, localizationService); this.routeValues = siteMapNodeChildStateFactory.CreateRouteValueDictionary(key, "RouteValues", siteMap); this.preservedRouteParameters = siteMapNodeChildStateFactory.CreatePreservedRouteParameterCollection(siteMap); this.roles = siteMapNodeChildStateFactory.CreateRoleCollection(siteMap); this.metaRobotsValues = siteMapNodeChildStateFactory.CreateMetaRobotsValueCollection(siteMap); }