SiteMapPath doesnt' show Web.sitemap siteMapNode with querystring in url - asp.net-2.0

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

Related

Asp.net intelligencia UrlRewriter with 2 querystring parameter (hiding one of them)

I'am using intelligencia.UrlRewriter on my web site.
I'am sending two querystring parameter to profil page.
<asp:HyperLink ID="lnkProfil" runat="server" Text='profil' NavigateUrl='/u/9f51e845-1089-4495-bd66-964db5b9c47b/tiju' ForeColor="Silver"></asp:HyperLink>
web config :
<rewrite url="~/u/(.+)/(.+)" to="~/Profil.aspx?user_id=$1&user_name=$2" />
and url seems like
http://yxyx.com/u/9f51e845-1089-4495-bd66-964db5b9c47b/tiju
But I want to make like
http://yxyx.com/u/tiju
or directly
http://yxyx.com/tiju (like facebook & twitter)
How can I hide user id parameter on url ?
If you want to have http://yxyx.com/u/tiju you should set it in the HyperLink
<asp:HyperLink ... NavigateUrl='/u/tiju' ...
In this case rewrite rule could be as
<rewrite url="~/u/(.+)" to="~/Profil.aspx?user_name=$1" />
As you see, in this case you will send only one parameter (tiju)

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 add more root level items to asp.net menu control?

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.

Binding unique URLs to XML site map ASP.NET

So, I'm new to ASP.NET and website development in general. I've run into a problem using data binding to an XML file to build a site map for an ASP.NET application. Here's the first portion of the sitemap:
<Privo>
<child display="Current Projects">
<child display="Amifostin">
<child display="Experiments">
<leaf>HTT</leaf>
<leaf>MTT</leaf>
<leaf>HPLC</leaf>
<leaf>UV-Spec</leaf>
</child>
And the data binding from the site.master file:
<DataBindings>
<asp:TreeNodeBinding DataMember="child" TextField="display" />
<asp:TreeNodeBinding DataMember="leaf" TextField="#InnerText" />
</DataBindings>
What'd I'd like to do it something like this:
<leaf url="ExperimentsView.aspx/HTT">HTT<leaf>
and
<asp:TreeNodeBinding DataMember="leaf" TextField="#InnnerText" NavigateUrl="url"/>
BUT, here's the problem: when I try to bind the NavigateUrl, the only thing I can do is bind a type of node to a url - meaning, every leaf will link the the same url. Is there a way to bind a field of the leaf nodes to a (unique) url, or will I have to make different DataMembers for each unique url?
Note: yes, I know about Web.sitemap. That's what I was using when the project lead told me that he wants to use XML data binding.
You will need to use the NavigateUrlField property to do this (see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treenodebinding.navigateurlfield.aspx)

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.

Resources