In ASP.NET, we often use site maps to set up navigation, particularly for menus. By default, the ASP.NET site-map provider uses the "Web.sitemap" file. Here is an example of this file for a simple site:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="Home" description="Home" url="~/default.aspx">
<siteMapNode title="Services" description="Services we offer" url="~/Services.aspx">
<siteMapNode title="Consulting" description="Consulting services" url="~/Consulting.aspx" />
<siteMapNode title="Support" description="Supports plans" url="~/Support.aspx" />
</siteMapNode>
<siteMapNode title="About Us" description="About Us" url="~/AboutUs.aspx">
<siteMapNode title="Company" description="Our people and offices" url="~/Company.aspx" />
<siteMapNode title="Blogs" description="Blogs from us to you"
url="http://blogs.mysite.com/default.aspx" />
</siteMapNode>
</siteMapNode>
</siteMap>
So our basic menu will look like this:
Home
Services
Consulting
Support
About Us
Company
Blogs
Notice that the "Blogs" node in the "About Us" section references an outside URL. This is not a problem, until you start adding role-base security to the site. Specifically, once you set you securityTrimmingEnabled="true" in the Web.config or the Web.sitemap file, the "Blogs" node disappears, and you're left scratching your head.
Home
Services
Consulting
Support
About Us
Company
At this point, you'll find that some developers get rid of the web.sitemap, and start hard coding menu items. However, there is a really easy fix for this behaviour. Just allow everyone access to the Blogs node so that it doesn't get trimmed:
<siteMapNode title="Blogs" description="Blogs from us to you"
url="http://blogs.mysite.com/default.aspx" roles="*">
By adding roles="*", we've got our blog back. That was almost too easy.
Just for completeness, I'm going to mention that we could have also just disabled the security trimming in the Web.sitemap file by adding securityTrimmingEnabled="false" to the Blogs node. Although I'm not a big fan of this method, as I find it makes the Web.sitemap less clear on what we're trying to accomplish, which is never good for the next guy working on the site, but the choice is yours.
Happy referencing,
James Fielding
Sciosoft Systems is a Canadian web design & development company based in Muskoka,
which is in central Ontario. We provide ASP.NET website & Windows Server application
development services to small and medium-sized business, as well as local government
and not-for-profit groups. If you have a website project you’d like to discuss,
please visit us at www.sciosoft.com.