How to add more root level items to asp.net menu control? - asp.net

Added a menu control and selected new datasource: SiteMapDataSource1
Here is my Web.sitemap so far:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Home.aspx" title="Home" description="Home Page">
<siteMapNode url="~/PostItem.aspx" title="Post Item" description="Post a new item" />
</siteMapNode>
</siteMap>
How can I add more root level items? I can create more siteMapNode's within the root level one that's already there, but if I add any outside of that it gives me an error. It makes sense to me why that would cause an error, but I'm thinking there's obviously a way to get the menu to display multiple root level menu items... but how?

--Edit--
If you want to build the Menu control with a xml data set, then you can have multiple nodes at the root level. This can be done via the designer and specifying MenuItems in the Items set of the Menu control, you can also add MenuItems to the Items list in the code behind, or bind it to an xml data set.
The MSDN has more information regarding this control. Code Project has a tutorial on using the xml data to build the Menu control.
--Original--
Sorry, you cannot add more than one root level siteMapNode. Typically you see that being the main entry point of the site (like you have it configured). Additional navigation is added from there.
Take a look at the MSDN for more information.

Related

Web.sitemap display links in function of role

I have one Web page , that can be only accessed if user has one of two allowed roles "Politician" or "Worker". Dependending from which user role is accessed the title of the web in the navigation sitemap has to be different.
In our web.config this page is configured to be accessed with the two roles "Politician" or "Worker", and in web.sitemap I have the next code.
<siteMapNode url="DoTask.aspx?Validator=Worker" title="TitleForRole" roles="Worker" />
<siteMapNode url="DoTask.aspx?Validator=Politician" title="TitleFolRoleB" roles="Politician" />
The problem is with that code is despite of user has only one of the roles in the sitemap appear the two links.
Is there a way to make only visible the link user has the role in sitemap?
One solution is create a page for one of the roles that redirect to DoTask.aspx and change sitemap
<siteMapNode url="DoTask.aspx?Validator=Worker" title="TitleForRole" roles="Worker" />
<siteMapNode url="RedirectToDoTask.aspx" title="TitleFolRoleB" roles="Politician" />
But I think this is not elegant solution, I would like to avoid to create another page.
Thanks for your help.
You can do it following the steps in http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx

How to move the documentactions viewlet from a viewletmanager to another?

Once again back with a Plone question.
I have Plone 4 installed and I need to show the Document action icons at the top instead of bottom. having trouble in getting this to work. can someone help.
If you just need to move that viewlet (with same class and template), first you have to register a viewlet with same class to your desired viewletmanager (let's say for ex. plone.app.layout.viewlets.interfaces.IAboveContentBody):
<browser:viewlet
name="plone.abovecontenttitle.documentactions"
manager="plone.app.layout.viewlets.interfaces.IAboveContentBody"
class="plone.app.layout.viewlets.content.DocumentActionsViewlet"
permission="zope2.View"
/>
and then add this in your genericsetup profile (file viewlets.xml) :
<?xml version="1.0"?>
<object>
<order manager="plone.abovecontentbody" skinname="Plone Default">
<!-- this will place your viewlet before all the others.
you can also use a viewlet's name for a relative position -->
<viewlet name="plone.abovecontenttitle.documentactions" insert-before="*"/>
</order>
<hidden manager="plone.belowcontentbody" skinname="Plone Default">
<viewlet name="plone.abovecontenttitle.documentactions"/>
</hidden>
</object>
More info:
http://plone.org/documentation/kb/customization-for-developers/viewlets
http://collective-docs.readthedocs.org/en/latest/views/viewlets.html

SiteMap change SiteMapProvider?

I've got a custom menu navigation built from a web.sitemap file, the first line of this would be something like:
SiteMapNodeCollection topLevelNodes = SiteMap.RootNode.ChildNodes;
This works - it gets all the top level nodes from the web.sitemap file, and allows me to look through each SiteMapNode and do stuff.
However, now I want to be able to create multiple web.sitemap files, and then programmatically determine which web.sitemap file to use, but I can't seem to find out how to do this. I'm assuming I could either create one custom SiteMapProvider that can perform the logic to determine which web.sitemap file to load, or I have multiple providers, each one with the SiteMapFile property set to a specific *.sitemap file, and then switch providers programmatically before I access SiteMap.RootNode.
I think it's probably easier to have one custom provider, and then override the part where it looks for the actual physical sitemap file location, but I'm unclear how I would do this
I've googled a lot, but most answers seem to be regarding the standard sitemappath controls and so on, and how to set a SiteMapDataSource, which I don't think is relevant to my approach.
First you need to specify all of your sitemap files in your web.config as such:
<siteMap defaultProvider="FNDSiteMap" enabled="true">
<providers>
<add name="FNDSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="FND.sitemap" securityTrimmingEnabled="true"/>
<add name="STASiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="STA.sitemap" securityTrimmingEnabled="true"/>
<add name="TASiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="TA.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
Then in your code-behind you can dynamically assign your SiteMapDataSource (which is bound to your menu) to one of the providers you specified in your web.config:
.aspx
<asp:Menu ID="MenuLevel1" runat="server" Orientation="Horizontal" DataSourceID="SiteMapLevel1"
MaximumDynamicDisplayLevels="0" IncludeStyleBlock="false">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapLevel1" runat="server" />
.cs
SiteMapLevel1.SiteMapProvider = "TASiteMap";
Pauli's comment was the answer to my particular requirement:
"You shouldn't switch/change anything... instead you need to access
the RootNode like this all the time
SiteMap.Providers[someProvider].RootNode and the someProvider should
then be resolved at runtime."
I hadn't realised this was possible, but was the correct solution for me.

how to exclude root node in XML for displaying menu?

I want to attach the xml file data to the menu through the XmlDataSource.
I did that but it display from root node. How to do if do not want root node menu. & all the sub menus in same level. eg File, Edit, View etc. Because not to do so then we get unnecessary one extra level for root level menu.
Regards,
Girish
Use the XmlDataSource.XPath property to specify the entry point to the data you want to show for example
XmlDataSource.XPath = "xml/submenus";
Modify the XPath to point to the correct tags in the xml file.
ASPX:
XPATH="ROOT/TARGET"
XML:
<ROOT>
<TARGET TEXT="STARTS HERE">
<DATA TEXT="OTHER DATA HERE" />
</TARGET>
</ROOT>

SiteMapPath doesnt' show Web.sitemap siteMapNode with querystring in url

I have the following web.sitemap portion:
<siteMapNode title="MENU" url="">
<siteMapNode url="~/page1.aspx?id=0" title="MENU 1" />
<siteMapNode url="~/page2.aspx" title="MENU 2" />
</siteMapNode>
When I am in http://localhost/page1.aspx I cannot see the map path because in my sitemap I have quesrystring ?id=0.
Can I fix it?
Thank you soo much!
Nicola
Now that there is a possibility to be in page1.aspx without any querystring so add it to your sitemap otherwise if there is not a way of use without querystrings. so what are you doing in page1.aspx alone? just don't let users to navigate to page1.aspx alone.
you want to display specific value in navigation bar so you cannot do that with that way you have more ways
1-use site map provider
2-make data source which retrieve data from stored procedure or method
I will send you example soon.
best regards

Resources