Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sitemap without Role Managements

Status
Not open for further replies.

avantgd

Programmer
Jan 22, 2002
16
US
I am relatively new to ASP.Net 2.0 and am working on an application for our company similar to ASP.Net Time Tracker 2.0. I want to use a similar web.sitemap but my web host does not allow role management to be enabled on our shared server. How do I create a similary sitemap, i.e. menu items are only displayed for certain user groups, without using role management. Any help is greatly appreciated!
 
you could create a custom SiteMapProvider and handle the role management yourself. I use a custom SiteMapProvider to "hide" accessible links. example:
web.config
Code:
<system.web>
   <siteMap defaultProvider="VisibleProvider" enabled="true">
      <providers>
         <clear/>
         <add name="VisibleProvider" description="Custom SiteMap Provider" type="SBI.SiteMapProvider.CustomSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/>
      </providers>
   </siteMap>
</system.web>
App_Code/MySiteMapProvider.cs
Code:
using System.Web;
namespace SBI.SiteMapProvider
{
   public class CustomSiteMapProvider : XmlSiteMapProvider
   {
      public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
      {
         SiteMapNodeCollection nodes = base.GetChildNodes(node);
         SiteMapNodeCollection returnNodes = new SiteMapNodeCollection(nodes);

         foreach (SiteMapNode n in nodes)
         {
            if (n["visible"] != null && n["visible"].Equals("false")) returnNodes.Remove(n);
         }
         return SiteMapNodeCollection.ReadOnly(returnNodes);
      }
   }
}
then use SiteMapDataSource or SiteMapPath object as you normally would.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you for the help and the sample code. I think I understand how it works. However, how do you handle setting the sitemap node to false in the web.sitemap?
 
does you mean how is the web.sitemap file formatted? like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="[URL unfurl="true"]http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"[/URL] >
  <siteMapNode url="Home.aspx" title="Home" visisble="true">
    <siteMapNode url="Work.aspx" title="Work" visisble="false" />
    <siteMapNode url="School.aspx" title="School" visisble="false" />
  </siteMapNode>
</siteMap>
also a quick google search for web.sitemap or custom web.sitemap turns has some great resources

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top