ASP.net sitemap fails to navigate? - asp.net

I am new to Asp.net and I had some trouble with menu navigation.
I had the Web.sitemap
<siteMapNode url="~/" title="Home" description="Home">
<siteMapNode url="~/Default" title="Home" description="Go to the homepage" />
<siteMapNode url="~/Reviews/Default" title="Reviews" description="Reviews published on this site">
<siteMapNode url="~/Reviews/AllByGenre" title="By Genre" description="All Reviews Grouped by Genre" />
<siteMapNode url="~/Reviews/All" title="All Reviews" description="All Reviews" />
</siteMapNode>
<siteMapNode url="~/About/Default" title="About" description="About this Site">
<siteMapNode url="~/About/Contact" title="Contact Us" description="Contact Us" />
<siteMapNode url="~/About/AboutUs" title="About Us" description="About Us" />
</siteMapNode>
<siteMapNode url="~/Login" title="Login" description="Log in to this web site" />
and the start page Default.aspx gives
But it just gives HTTP Error 404.0 not found errorwhen I try to navigate. URL is http://localhost:24186/About/AboutUs

url ="~/About/Default" . Try add the .aspx like
url="~/About/Default.aspx"
I am not sure though. Cant see issue otherwise. I normally add the .aspx and i think it should be there.

Related

.net Menu control SelectedItem always null on homepage

I am using a .net webforms Menu control generated from the following sitemap:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="NavigationWrapper" description="">
<siteMapNode url="/" title="Home" description="" />
<siteMapNode url="/search" title="Search" description="" />
<siteMapNode url="/contact" title="Contact" description="" />
</siteMapNode>
</siteMap>
When I click the home link, the SelectedItem property of the menu control is always null, but it works fine when clicking the other two links. I can't seem to work out why!
The only way I can seem to get around this is to create a www.abc.com/home link for my homepage, but I'd prefer not to do that.
Any help much appreciated!
Edit:
Route Collection is as follows:
routes.MapPageRoute("Home", "", "~/Default.aspx");
routes.MapPageRoute("Search", "search", "~/SearchByMap.aspx");
routes.MapPageRoute("contact", "contact", "~/Contact.aspx");
Try this:
<siteMapNode url="~/" title="Home" description="">
<siteMapNode url="/search" title="Search" description="" />
<siteMapNode url="/contact" title="Contact" description="" />
</siteMapNode>
Add this to your route collection:
public static void RegisterRoutes(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("Home", "", "~/Default.aspx");
}

The securityTrimmingEnabled="true" in web.config works too good

I'm using C# ASP.NET 4 VS2010.
I'm using membership with roles, which are already defined as usual.
I have a ~/web.sitemap file that includes this:
(The ~/ security is Allow to all.)
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode url="" title="A menu for the Administrator" description="">
<siteMapNode url="~/Admin/ResetPassword.aspx" title="Reset password for a user" description="" />
<siteMapNode url="~/Admin/SendEmailToUser.aspx" title="Send e-mail to a user" description="" />
</siteMapNode>
<siteMapNode url="" title="A menu for the SIC (second in command) person" description="">
<siteMapNode url="~/SIC/UnlockUser.aspx" title="Unlock a user" description="" />
<siteMapNode url="~/SIC/ApproveUser.aspx" title="Approve a user" description="" />
</siteMapNode>
<siteMapNode url="" title="A menu for users" description="">
<siteMapNode url="~/Users/MakeYourContribute.aspx" title="Make your contribution" description="" />
<siteMapNode url="~/Users/CheckOnYourBalance.aspx" title="Check on your balance" description="" />
</siteMapNode>
<siteMapNode url="" title="A menu for anonymous visitors" description="">
<siteMapNode url="~/AboutUs.aspx" title="About us" description="" />
<siteMapNode url="~/Application.aspx" title="Send an application to join us" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>
and a web.config file that ends like this:
<siteMap defaultProvider="XmlSiteMapProvider" enabled ="true">
<providers>
<add name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider" siteMapFile="~/web.sitemap" securityTrimmingEnabled="true" />
</providers>
</siteMap>
</system.web>
</configuration>
My menu is based on the asp:Repeater control and looks like this:
<div>
<ul>
<li>
<asp:hyperlink runat="server" id="lnkHome" navigateurl="~/Default.aspx">Home</asp:hyperlink>
</li>
<asp:repeater runat="server" id="menu" datasourceid="SiteMapDataSource1">
<ItemTemplate>
<li>
<asp:HyperLink ID="lnkMenuItem" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
<asp:Repeater ID="submenu" runat="server" DataSource="<%# ((SiteMapNode) Container.DataItem).ChildNodes %>">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink ID="lnkMenuItem" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate> </asp:Repeater> </li> </ItemTemplate> </asp:Repeater> </ul>
<asp:sitemapdatasource id="SiteMapDataSource1" runat="server" showstartingnode="true" />
</div>
The security of allow/deny to folders is defined for the respective folders.
There are 4 levels of security: 1) Administrators. 2)Second In Command (SIC). 3) Users (all registered users). 4) Anonymous users.
For example, both the members of the Administrators role and the SIC role are allowed on the operate in the folder ~/SIC , but the rest of the users are restricted from it.
Now, as soon as I added the securityTrimmingEnabled="true" to the web.config, the only row I see on the menu is Home.
Have I configured anything wrong?
Are there any more configuration I need to make in order to have this security dependent menu work?
The problem is the empty URL in the menu headers.
<siteMapNode url="" title="A menu for the Administrator" description="">
It appears that the sitemap functionality is trying to determine the permissions for the empty url "", and failing.
A workaround is to modify the .sitemap file to explicitly state the roles that can access the parent nodes.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="" roles="*">
<siteMapNode url="" title="A menu for the Administrator" description="" roles="Administrators">
<siteMapNode url="~/Admin/ResetPassword.aspx" title="Reset password for a user" description="" />
<siteMapNode url="~/Admin/SendEmailToUser.aspx" title="Send e-mail to a user" description="" />
</siteMapNode>
<siteMapNode url="" title="A menu for the SIC (second in command) person" description="" roles="administrators,second in command">
<siteMapNode url="~/SIC/UnlockUser.aspx" title="Unlock a user" description="" />
<siteMapNode url="~/SIC/ApproveUser.aspx" title="Approve a user" description="" />
</siteMapNode>
<siteMapNode url="" title="A menu for users" description="" roles="administrators,secondincommand,users">
<siteMapNode url="~/Users/MakeYourContribute.aspx" title="Make your contribution" description="" />
<siteMapNode url="~/Users/CheckOnYourBalance.aspx" title="Check on your balance" description="" />
</siteMapNode>
<siteMapNode url="" title="A menu for anonymous visitors" description="" roles="*">
<siteMapNode url="~/AboutUs.aspx" title="About us" description="" />
<siteMapNode url="~/Application.aspx" title="Send an application to join us" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>
Admittedly, this isn't ideal, because now you are partially configuring security in two places.
Another option is to just put roles="*" on every menu header. It will still apply the permissions check on every leaf node and hide them if necessary. The downside to this is that it can then display empty menu headers.
Here is the resource which pointed me to this solution: https://web.archive.org/web/20210417091658/http://www.4guysfromrolla.com/articles/122805-1.aspx

How to combine web.sitemap and SiteMapProvider in ASP.NET

So, here's what I'm working on. I have an ASP.NET web app, in which the sitemap is displayed on the site.master file through the web.sitemap.
Here's the site.master:
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView
ID="TreeView1"
runat="server"
ataSourceID="SiteMapDataSource1"
ExpandDepth="1">
</asp:TreeView>
And here's the web.sitemap:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home" description="Home">
<siteMapNode url="" title="Projects" description="">
</siteMapNode>
<siteMapNode url="" title="Configurations" description="Configurations">
<siteMapNode url="" title="Experiments" description="Experiments">
</siteMapNode>
<siteMapNode url="" title="Cell Line" description =""></siteMapNode>
<siteMapNode url ="" title ="Drugs">
</siteMapNode>
<siteMapNode url ="" title="Manage Configurations" />
<siteMapNode url="~/ExperimentConfigurationView.aspx" title ="Configure Experiements"/>
<siteMapNode url="~/DrugConfigurationView.aspx" title="Configure Drugs"/>
</siteMapNode>
</siteMapNode>
<siteMapNode url="" title="Drug Recipes" description="">
</siteMapNode>
</siteMapNode>
</siteMap>
Now, here's where I'm running into a problem. What I'd like to do is combine this site map with a dynamically created SiteMapProvider, and populate the sub-trees of this map. For example, the Projects, Experiments, Cell Line and Drug Recipe nodes would each have a sub-tree, populated from a datebase. Anyone have input, or a suggestion as to where to start looking?
In summary - I'd like to point the leaf siteMapNodes to a SiteMapProvider.
Solution:
I added a file DrugListProvider.cs in the root directory. That holds the code for dynamically generating the sub-tree.
I placed the following node in the Web.sitemap, where I wanted the sub-tree to appear:
<siteMapNode provider="DrugListProvider"/>
Finally, I include this in the web.config file:
<siteMap>
<providers>
<add name="DrugListProvider" type="PrivoWeb.DrugListProvider"/>
</providers>
</siteMap>

Setting role in SiteMapNode Sub Node

These Site Map Node is in Web.Config
<siteMapNode title="Hotel Setup" roles="Administrator,Hotel Admin">
<siteMapNode url="~/Page/HotelSetup/RoomTypeManagement.aspx" title="Room Types" />
<siteMapNode url="~/Page/HotelSetup/AddOns/AddOnCategoryProperties.aspx" title="Add On Categories" />
<siteMapNode url="~/Page/HotelSetup/AddOn.aspx" title="Add Ons" />
<siteMapNode url="~/Page/HotelSetup/Package.aspx" title="Packages" />
<siteMapNode url="~/Page/PriceTools/Promotion.aspx" title="Promotions" />
<siteMapNode url="~/Page/PriceTools/PromotionAddOn.aspx" title="AddOns Incentive" />
<siteMapNode url="~/Page/SupportAdmin/TranslationProperty.aspx" title="Translations" />
</siteMapNode>
Is there anyway to made some sub sitemapnode in hotel setup can be accessed only by administrator but not hotel admin ?
Problem solved, it need to be set in location path

Breadcrumbs SiteMapPath and SEO-Friendly Routing

I have routing set up as follows:
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("", "Home", "~/Default.aspx");
......
}
I'm implementing breadcrumbs using a SiteMapPath control:
<asp:SiteMapPath ID="SiteMapPath1" CssClass="breadCrumbs" runat="server">
</asp:SiteMapPath>
Web.sitemap is set up as follows:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Home" title="Home" description="Home">
<siteMapNode url="~/About" title="About" description="About">
<siteMapNode url="~/History" title="History"
description="History" />
</siteMapNode>
</siteMapNode>
</siteMap>
My problem is that when I navigate to mysite.com instead of mysite.com/default.aspx, the Home breadcrumb node does not appear. What am I missing?
UPDATE
I managed to get the "Home" node to display by updating Web.sitemap as follows:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Home" title="Home" description="Home">
<siteMapNode url="~/Default.aspx" title="" description="" />
<siteMapNode url="~/About" title="About" description="About">
<siteMapNode url="~/History" title="History"
description="History" />
</siteMapNode>
</siteMapNode>
</siteMap>
The only remaining problem is that the path separator is still displaying on home page for mysite.com
Is there a way to programatically render the separator invisible for the home page? The SiteMapPath control itself is in a master page.
Maybe you should change your sitemap file as follows :
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/" title="Global Site Name or Welcome Message" description="Home">
<siteMapNode url="~/Home" title="Home" description="" />
<siteMapNode url="~/About" title="About" description="About">
<siteMapNode url="~/History" title="History"
description="History" />
</siteMapNode>
</siteMapNode>
</siteMap>
and from the sitemapdatasource you should set ShowStartingNode="false" and I think that this solves both of your problems at once...
NOTE: of course this will require that you made this change in the global.asax file (VB):
RouteTable.Routes.MapPageRoute("Home0", "", "~/Default.aspx", True)
RouteTable.Routes.MapPageRoute("Home1", "Home", "~/Default.aspx", True)
hope this helps...

Resources