ramya
ramya

Reputation: 2760

Multiple root node in asp.net SiteMapPath (Web.sitemap)

I am implementing a Dashboard kind of web application, where users having different Roles. I have to show Site Map Path at the top pf the page, as user browse the different pages inside the dashboard. I am using asp.net SiteMapPath, how can i use it for Multiple root node. i need to implement multiple root node as per users roles.

Ex:- Admin->Directory1->Directory2->Page1.aspx

Teacher->Directory1->Page2.aspx

Student->Directory2->Page1.aspx and so on.

Where Admin, Teacher, and Student are root node of the path.

It shouldn't be like Admin->Teacher->Directory1->Page2.aspx

Any solution?

Thanks.

Upvotes: 1

Views: 2307

Answers (2)

ShaharB
ShaharB

Reputation: 186

you can use the admin as your root node, and define everything in the asp:Menu, in your case, use <asp:Menu ID="mainMenu" DataSourceId="siteMapDataSource" runat="server" StaticDisplayLevels="2" StaticSubMenuIndent="0" /> the StaticDisplayLevels="2" will make sure admin, teacher and student are always presented, and the indent will prevent it from appearing indented, as it is defined by default.

Upvotes: 1

Princee Singhal
Princee Singhal

Reputation: 29

  • three site Map file (For Admin, Teacher, Student) We've placed these sitemap files into the App_Data folder, In the user control, we create a public enum, to represent the different menus available.

    public enum SiteMapMenus  
    

    { Admin, Teacher, Student , NotSet }

    • Then created a public property to set the menu type at design time.
SiteMapMenus eMenuToLoad = SiteMapMenus.NotSet;  
public SiteMapMenus MenuToLoad  
{  
    get { return eMenuToLoad; }  
    set { eMenuToLoad = value; }  
}  
  • Now, The GetMenuDataSource method reads the required sitemap file as an XML file, then creates and returns a data source that can be bound to the control.

    XmlDataSource GetMenuDataSource(SiteMapMenus menu, string serverMapPath)  
    {  
        XmlDataSource objData = new XmlDataSource();  
        objData.XPath = "siteMap/siteMapNode";  
       switch (menu)  
       {  
    case SiteMapMenus.Admin:objData.DataFile=serverMapPath + @"\App_Data\Admin.sitemap";  
            break;  
        case SiteMapMenus.Teacher:
    objData.DataFile=serverMapPath+@"\App_Data\Teacher.sitemap";  
                     break;  
                case SiteMapMenus.Student:
    objData.DataFile=serverMapPath+@"\App_Data\Student.sitemap";  
                    break;  
        default:  
            break;  
    }  
    objData.DataBind();  
    return objData;  
    }  
    
  • as the data source is now XML, and not in the format returned from the sitemap provider, we need to setup our databindings on the menu control itself.

    <asp:Menu ID="Menu1" runat="server">     
 <DataBindings>   
         <asp:MenuItemBinding DataMember="siteMapNode" 
         TextField="title" NavigateUrlField="url"  />   
    </DataBindings>   
 </asp:Menu>  
  • We can now finally bind the source to the control, and this is all fired off in the Page_Load event handler of the User Control.

    protected void Page_Load(object sender, EventArgs e)  
      {  
         Menu1.DataSource = GetMenuDataSource(eMenuToLoad, 
                            Server.MapPath("~"));  
         Menu1.DataBind();  
      }  
    
  • Using our new menu is now as easy as registering the user control on the page, and specifying which menu to display by setting the MenuToLoad property.

       <DW:MyMenu ID="MyMenu1" runat="server" MenuToLoad="Secure" />
    

Now, You can use different different site map for different different users.....

Upvotes: 0

Related Questions