ASP.NET 2.0数据教程:添加站点地图

开发 后端
本文介绍在asp.net 2.0中如何添加站点地图。

管理一个由大量网页组成的网站的其中一个挑战是要为访问者浏览网站提供一个捷径。作为开始,站点的导航结构必须被定义。下一步,这个结构必须转换成适于导航的用户界面元素,比如菜单或者位置导航。当有新页面添加到站点和已有的页面被移除的时候这个过程将要修改和校正。

在asp.net 2.0以前,开发者需要自己创建站点导航结构,维护它并且将它转化为适于导航的用户界面元素。在asp.net 2.0里,开发者可以利用非常灵活的且内置的站点导航系统。asp.net 2.0站点导航系统允许开发者定义一个站点地图并且提供了可以访问这些信息的API。

默认的asp.net站点地图提供者期望站点地图信息存储在xml格式的文件中。但是,建立在提供者模型上的站点导航系统是可以被扩展的以支持多种方式储存的站点地图。Jeff Prosise的文章,The SQL Site Map Provider You’ve Been Waiting For展示了怎样创建将站点地图存储在SQL Server数据库里的提供者;另外一个选择是基于文件系统的站点地图提供者。

在这个指南中,我们仍然使用asp.NET2.0里默认的站点地图提供者。要创建站点地图,在解决方案管理器里右键点击项目名称,选择添加新项,然后选择站点地图类型。命名为Web.sitemap然后单击添加按钮,则是添加站点地图。

向你的项目中添加站点地图 

图9:向你的项目中添加站点地图

站点地图文件是一个xml文件。注意:Visual Studio可以为站点地图结构提供智能感知。站点地图文件必须含有< siteMap>作为根节点,它必须至少含有一个< siteMapNode>子节点。这个< siteMapNode>元素又可以包含任意数量的< siteMapNode>子元素。

站点地图模拟了文件系统。为每个文件夹添加一个< siteMapNode>元素,并且为每个aspx页面添加一个< siteMapNode>子元素,如此:

Web.sitemap: 

  1. < ?xml version="1.0" encoding="utf-8" ?>  
  2.  < siteMap xmlns="http://schemas.microsoft.com/aspNet/SiteMap-File-1.0" >  
  3.    
  4.    < siteMapNode url="~/Default.aspx" title="Home" description="Home">  
  5.        < siteMapNode title="Basic Reporting" 
  6.          url="~/BasicReporting/Default.aspx" 
  7.          description="Basic Reporting Samples">  
  8.          < siteMapNode url="~/BasicReporting/SimpleDisplay.aspx" 
  9.           title="Simple Display" 
  10.          description="Displays the complete contents  
  11.           of a database table." />  
  12.         < siteMapNode url="~/BasicReporting/DeclarativeParams.aspx" 
  13.           title="Declarative Parameters" 
  14.           description="Displays a subset of the contents  
  15.             of a database table using parameters." />  
  16.         < siteMapNode url="~/BasicReporting/ProgrammaticParams.aspx" 
  17.          title="Setting Parameter Values" 
  18.          description="Shows how to set parameter values  
  19.           programmatically." />  
  20.       < /siteMapNode>  
  21.  
  22.       < siteMapNode title="Filtering Reports" 
  23.        url="~/Filtering/Default.aspx" 
  24.        description="Samples of Reports that Support Filtering">  
  25.         < siteMapNode url="~/Filtering/FilterByDropDownList.aspx" 
  26.           title="Filter by Drop-Down List" 
  27. description="Filter results using a drop-down list." />  
  28.         < siteMapNode url="~/Filtering/MasterDetailsDetails.aspx" 
  29.          title="Master-Details-Details" 
  30.          description="Filter results two levels down." />  
  31.         < siteMapNode url="~/Filtering/DetailsBySelecting.aspx" 
  32.           title="Details of Selected Row" 
  33. description="Show detail results for a selected item in a GridView." />  
  34.       < /siteMapNode>  
  35.  
  36.       < siteMapNode title="Customized Formatting" 
  37.          url="~/CustomFormatting/Default.aspx" 
  38.          description="Samples of Reports Whose Formats are Customized">  
  39.         < siteMapNode url="~/CustomFormatting/CustomColors.aspx" 
  40.          title="Format Colors" 
  41.          description="Format the grid&apos;s colors based  
  42.            on the underlying data." />  
  43.         < siteMapNode  
  44.           url="~/CustomFormatting/GridViewTemplateField.aspx" 
  45.           title="Custom Content in a GridView" 
  46.           description="Shows using the TemplateField to  
  47.           customize the contents of a field in a GridView." />  
  48.         < siteMapNode  
  49.           url="~/CustomFormatting/DetailsViewTemplateField.aspx" 
  50.           title="Custom Content in a DetailsView" 
  51.           description="Shows using the TemplateField to customize  
  52.            the contents of a field in a DetailsView." />  
  53.         < siteMapNode url="~/CustomFormatting/FormView.aspx" 
  54.           title="Custom Content in a FormView" 
  55.           description="Illustrates using a FormView for a  
  56.            highly customized view." />  
  57.         < siteMapNode url="~/CustomFormatting/SummaryDataInFooter.aspx" 
  58.           title="Summary Data in Footer" 
  59.           description="Display summary data in the grids footer." />  
  60.       < /siteMapNode>  
  61.  
  62.   < /siteMapNode>  
  63.  
  64. < /siteMap> 

站点地图定义了这个站点的导航结构,它是层次结构的以便描述站点中各种各样的区域。在Web.sitemap中的每个< siteMapNode>元素描述了一个站点结构中的一个区域。

asp.net通过DotNET 框架中的SiteMap类显示站点地图的结构。这个类有一个CurrentNode属性,它返回当前用户正在访问的节点的信息;RootNode属性返回站点地图的根节点信息(在我们的站点地图中是Home)。CurrentNode呵RootNode属性都返回SiteMapNode实例,SiteMapNode包含ParentNode,ChildNodes,NextSibling,PreviousSibling等属性。添加站点地图后,这些属性允许站点地图的层次可以被遍历。

【编辑推荐】

  1. ASP.NET MVC路径选择系统构建
  2. ASP.NET MVC框架中的URL路径选择场景
  3. ASP.NET MVC 框架URL路径选择规则
  4. ASP.NET MVC框架:使用强类型类来传递ViewData
  5. 使用ASP.NET MVC框架创建电子商务网站

 

责任编辑:book05 来源: 博客园
相关推荐

2009-07-24 16:55:53

添加aspx页面

2009-07-27 03:21:00

breadcrumb导

2009-07-27 09:28:55

TableAdapte

2009-07-27 08:51:24

ObjectDataS

2009-07-24 17:15:52

SiteMapData

2009-07-24 13:08:03

BLL类ASP.NET 2.0

2009-07-24 13:08:52

DataRowASP.NET 2.0

2009-07-27 09:35:57

业务逻辑层

2009-07-24 14:23:16

定制编码DAL

2009-07-27 16:09:05

GridView显示数

2009-07-24 12:41:21

BLL类

2009-07-24 16:37:04

创建母版页asp.net 2.0

2009-07-27 09:01:44

ObjectDataS

2009-07-27 16:22:54

GridView选择行

2009-07-24 13:25:43

创建数据访问层

2010-06-25 08:51:46

ASP.NET MVC

2009-07-27 03:23:00

Default.asp

2009-07-24 13:45:28

添加参数化

2009-07-27 09:39:04

SelectMetho

2009-07-23 14:43:24

数据源控件ASP.NET 2.0
点赞
收藏

51CTO技术栈公众号