ASP. NET 2.0 data Tutorial: Add a site map

Source: Internet
Author: User

One of the challenges in managing a website composed of a large number of webpages is to provide a shortcut for visitors to browse the website. As the start, the navigation structure of the site must be defined. Next, the structure must be converted to a user interface element suitable for navigation, such as menu or location navigation. When a new page is added to the site and an existing page is removed, this process will be modified and corrected.

Before asp.net 2.0, developers needed to create their own site navigation structure, maintain it, and convert it into user interface elements suitable for navigation. In asp.net 2.0, developers can use a flexible and built-in site navigation system. The asp.net 2.0 site navigation system allows developers to define a site map and provides APIs to access this information.

The default asp.net site map provider expects that the site map information is stored in an xml file. However, the site navigation system built on the provider model can be expanded to support multiple storage methods. In Jeff Prosise's article, The SQL Site Map Provider You 've ve Been Waiting For shows how to create a Provider that stores Site maps in The SQL Server database; another option is the website map provider based on the file system.

In this guide, we still use the default site map provider in asp. NET2.0. To create a site map, right-click the project name in solution manager, select Add new item, and select the site map type. Name it Web. sitemap and click the Add button to add a site map.

 

Figure 9: Add a site map to your project

The site map file is an xml file. Note: Visual Studio provides intelligent sensing for the site map structure. The site map file must contain at least one <siteMapNode> subnode. The <siteMapNode> element can contain any number of <siteMapNode> sub-elements.

The site map simulates the file system. Add a <siteMapNode> element to each folder and add a <siteMapNode> sub-element to each aspx page:

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> 

A site map defines the navigation structure of the site, which is hierarchical to describe various areas of the site. Each <siteMapNode> element in Web. sitemap describes a region in a site structure.

Asp.net uses the SiteMap class in the DotNET framework to display the structure of the site map. This class has a CurrentNode attribute, which returns the information of the node currently accessed by the user; The RootNode attribute returns the information of the root node of the site map in our site map is Home ). The CurrentNode and RootNode attributes all return SiteMapNode instances. SiteMapNode includes ParentNode, ChildNodes, NextSibling, previussibling, and other attributes. After a site map is added, these attributes allow the layers of the site map to be traversed.

  1. ASP. net mvc Path Selection System Construction
  2. URL path selection scenario in ASP. net mvc Framework
  3. URL path selection rules of ASP. net mvc Framework
  4. ASP. net mvc Framework: Use a strong type class to pass ViewData
  5. Use ASP. net mvc framework to create an e-commerce website

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.