简体   繁体   English

ASP.NET SiteMapPath(Web.sitemap)中的多个根节点

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

I am implementing a Dashboard kind of web application, where users having different Roles. 我正在实现仪表板类型的Web应用程序,其中用户具有不同的角色。 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. 我正在使用asp.net SiteMapPath,如何将其用于多个根节点。 i need to implement multiple root node as per users roles. 我需要根据用户角色实施多个根节点。

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

Teacher->Directory1->Page2.aspx 教师->目录1-> Page2.aspx

Student->Directory2->Page1.aspx and so on. Student-> Directory2-> Page1.aspx,依此类推。

Where Admin, Teacher, and Student are root node of the path. 其中“管理员”,“教师”和“学生”是路径的根节点。

It shouldn't be like Admin->Teacher->Directory1->Page2.aspx 它不应该像Admin-> Teacher-> Directory1-> Page2.aspx

Any solution? 有什么办法吗?

Thanks. 谢谢。

您可以使用admin作为根节点,并在asp:Menu定义所有内容,在您的情况下,请使用<asp:Menu ID="mainMenu" DataSourceId="siteMapDataSource" runat="server" StaticDisplayLevels="2" StaticSubMenuIndent="0" /> StaticDisplayLevels="2"将确保始终显示admin,教师和学生,并且缩进将防止其显示为缩进,这是默认情况下定义的。

  • 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. 三个站点地图文件(用于管理员,教师,学生)我们已将这些站点地图文件放入App_Data文件夹中,在用户控件中,我们创建了一个公共枚举,以表示可用的不同菜单。

     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. 现在,GetMenuDataSource方法将所需的站点地图文件读取为XML文件,然后创建并返回可以绑定到控件的数据源。

     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. 由于数据源现在是XML,而不是站点地图提供程序返回的格式,因此我们需要在菜单控件本身上设置数据绑定。

  <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. 现在,我们终于可以将源绑定到控件了,所有这些都在用户控件的Page_Load事件处理程序中触发。

     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. 现在,使用我们的新菜单就像在页面上注册用户控件并通过设置MenuToLoad属性指定要显示的菜单一样容易。

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

Now, You can use different different site map for different different users..... 现在,您可以为不同的用户使用不同的站点地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM