如何使用菜单控件在一个网站中配置多个站点地图 [英] How to configure the multiple sitemaps in one website with menu control

查看:140
本文介绍了如何使用菜单控件在一个网站中配置多个站点地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我已经开发了asp.net项目。这个项目有两个成员

admin,student.i维护了两个母版页,并为成员活动(管理员,学生)提供了相应的菜单控件.i使用了两个站点地图文件(Web.sitemap,student.sitemap)

i在一个Web配置文件中配置了多个站点地图。我使用站点地图将学生成员活动绑定到菜单控件(在学生主页中)但是而不是管理活动自动绑定到学生母版页,即功能第二菜单不能正常工作。两个母版页也绑定管理活动,但我想通过使用站点地图和菜单控件绑定相应母版页的活动。



Web.sitemap





Actually i had develop the asp.net project.This project has two members
admin,student.i had maintain two master pages with corresponding menu controls for member activities(admin,student).i used two sitemap files (Web.sitemap,student.sitemap)
i was configure the multiple sitemaps in one web configure file.i bind the student member activities to menu control(with in student masterpage)using sitemap but instead of admin activities are bind automatically to student master page i.e functionality second menu not working properly.two master pages are also bind the admin activities but i want to bind the activities for corresponding master pages by using sitemap and menu control.

Web.sitemap


<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="" title=""  description="">
         <siteMapNode url="Admin.aspx" title="Home"  description="Home page" />
        <siteMapNode url="StudentRegistration.aspx" title="Student registration"  description="Studentregistration page" />
         <siteMapNode url="AddLearningmaterial.aspx" title="Add material" description="AddLearningmaterial">
             <siteMapNode url="Alphabets.aspx" title="Alphabets" description="Alphabets page"></siteMapNode>
             <siteMapNode url="Numbers.aspx" title="Numbers" description="Numbers page"></siteMapNode>
             <siteMapNode url="Animals.aspx" title="Animals" description="Animals page"></siteMapNode>
             <siteMapNode url="Fruits.aspx" title="Fruits" description="Fruits page"></siteMapNode>
             <siteMapNode url="Vegetables.aspx" title="Vegetables" description="Vegetables page"></siteMapNode>
         </siteMapNode>
        <siteMapNode url="Modifyingmaterial.aspx" title="Update material" description="Modifyingmaterial page"></siteMapNode>
    <!--<siteMapNode siteMapFile="student.sitemap"/>-->      
    </siteMapNode>
</siteMap>





student.sitemap



student.sitemap

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 <siteMapNode url="" title=""  description="">
  <siteMapNode url="Home.aspx" title="Home"  description="Home page" />
  <siteMapNode url="Viewmaterial.aspx" title="View material"  description="Viewmaterial page" >
    <siteMapNode url="ViewAlphabets.aspx" title="Alphabets" description="Alphabets page"></siteMapNode>
    <siteMapNode url="viewNumbers.aspx" title="Numbers" description="Numbers page"></siteMapNode>
    <siteMapNode url="viewAnimals.aspx" title="Animals" description="Animals page"></siteMapNode>
    <siteMapNode url="viewFruits.aspx" title="Fruits" description="Fruits page"></siteMapNode>
    <siteMapNode url="viewVegetables.aspx" title="Vegetables" description="Vegetables page"></siteMapNode>
   </siteMapNode>
    </siteMapNode>
</siteMap>





在webconfig中配置多个站点地图文件:



Configure multiple site maps in webconfig File:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <siteMap defaultProvider="SiteMapDataSource1">
      <providers>
        <clear/>
       <add name="SiteMapDataSource1" type="System.Web.XmlSiteMapProvider" siteMapFile="Web.sitemap" />
    <add name="SiteMapDataSource2" type="System.Web.XmlSiteMapProvider" siteMapFile="student.sitemap" />
      </providers>
    </siteMap>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
</configuration>









管理员。 master





Admin.master:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Admin.master.cs" Inherits="Admin" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 <style type="text/css">
    body
    {
        font-family: Arial;
        font-size: 10pt;
    }
    .main_menu
    {
        width:240px;
        font-size:x-large;
        background-color: #8AE0F2;
        color: #000;
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-right: 5px;
    }
    .level_menu
    {
        width:257px;
        font-size:large;
        background-color: #000;
        color: #fff;
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-top: 5px;
    }

    .selected
    {
        background-color: #852B91;
        color: #fff;
    }
    /*.sub_menu
   {
        width: 110px;
        background-color: #000;
        color: #fff;
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-top: 5px;
   }
    .hover_menu
   {
        background-color: #990000;
        color:#fff;
   }
    .selected_menu
   {
      background-color: #FF6600;
   }*/
</style>
    <asp:ContentPlaceHolder id="head" runat="server">

    </asp:ContentPlaceHolder>
</head>
<body>
   <form id="form1" runat="server">
    <asp:Image ID="ImgELearn"  runat="server" AlternateText="E-Learning" Height="202px" ImageUrl="~/Images/Title logo.png" Width="1020px"  />    
       <div class="user">
           <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
           <asp:Menu ID="Menu" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
    OnMenuItemDataBound="OnMenuItemDataBound">
    <LevelMenuItemStyles>
        <asp:MenuItemStyle CssClass="main_menu" />
        <asp:MenuItemStyle CssClass="level_menu" />       
    </LevelMenuItemStyles>
 <%--<DynamicMenuItemStyle CssClass="sub_menu" />
<DynamicHoverStyle CssClass="hover_menu" />
<StaticSelectedStyle CssClass="selected_menu" />
<StaticHoverStyle CssClass="hover_menu" />--%>

</asp:Menu>
       </div>  
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>







Student.master:




Student.master:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Student.master.cs" Inherits="Student" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
 <form id="form1" runat="server">
    <asp:Image ID="ImgELearn"  runat="server" AlternateText="E-Learning" Height="202px" ImageUrl="~/Images/Title logo.png" Width="1020px"  />
     <div class="data">
      <asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" ShowStartingNode="false" />
         <%--<asp:SiteMapPath ID="SiteMapPath1"  runat="server" PathSeparator=" > " RenderCurrentNodeAsLink="false">
</asp:SiteMapPath>--%>
         <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource2" Orientation="Horizontal"
    OnMenuItemDataBound="OnMenuItemDataBound">
    <LevelMenuItemStyles>
        <asp:MenuItemStyle CssClass="main_menu" />
        <asp:MenuItemStyle CssClass="level_menu" />       
    </LevelMenuItemStyles>
       </asp:Menu>
         
     </div>
 
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>





这是我的代码。我认为开发项目的方式是正确的但我感觉很小

错误根据站点地图,菜单控制和web.config配置。如果你知道,请更正代码。我不知道什么是xmlsitemap defaultProvider .pls给我关于defaultProvider的信息,并详细说明添加标签中的名称属性。

i confused name attributes命名我是什么given.pls check once.help me。



我尝试过:





This is my code.I think way of developing the project is correct but i felt small
mistake according sitemap,menu control and web.config configuration.if u know,pls correct the code. i don't know what is the xmlsitemap defaultProvider.pls give me about defaultProvider and also give about name attributes in add tag in detail.
i confused name attributes names what i am given.pls check once.help me.

What I have tried:

i was configure the multiple sitemaps in one web configure file.i bind the student member activities to menu control(with in student masterpage)using sitemap but instead of admin activities are bind automatically to student master page i.e functionality of second menu not working properly.two master pages are also bind the admin activities but i want to bind the activities for corresponding master pages by using sitemap and menu control.

推荐答案

SiteMapDataSource 控制 [ ^ ]将绑定到默认站点地图提供程序在 web.config 文件中。



您已设置 defaultProvider =SiteMapDataSource1 ,指向 Web.sitemap ,因此 SiteMapDataSource 控件将使用该网站默认情况下映射。



要使用其他站点地图,您需要设置 SiteMapProvider property [ ^ ]到你想要使用的站点地图提供者的名字:

The SiteMapDataSource control[^] will, by default, bind to the default site map provider, as specified in the web.config file.

You've set defaultProvider="SiteMapDataSource1", which points to Web.sitemap, so both SiteMapDataSource controls will use that site map by default.

To use a different site map, you need to set the SiteMapProvider property[^] to the name of the site map provider you'd like to use:
<asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" 
    ShowStartingNode="false" 
    SiteMapProvider="SiteMapDataSource2"
/>



注意: ID SiteMapDataSource 控件的未以任何方式连接到站点地图提供程序的名称。将两者设置为相同的字符串将不会连接它们。更改提供程序的唯一方法是在标记中使用 SiteMapProvider 属性,或 提供商属性 [ ^ ]。


NB: The ID of the SiteMapDataSource control is not connected in any way to the name of the site map provider. Setting both to the same string won't connect them. The only way to change the provider is to use the SiteMapProvider property in markup, or the Provider property[^] from your code-behind.


这篇关于如何使用菜单控件在一个网站中配置多个站点地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆