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:
- < ?xml version="1.0" encoding="utf-8" ?>
- < siteMap xmlns="http://schemas.microsoft.com/aspNet/SiteMap-File-1.0" >
-
- < siteMapNode url="~/Default.aspx" title="Home" description="Home">
- < siteMapNode title="Basic Reporting"
- url="~/BasicReporting/Default.aspx"
- description="Basic Reporting Samples">
- < siteMapNode url="~/BasicReporting/SimpleDisplay.aspx"
- title="Simple Display"
- description="Displays the complete contents
- of a database table." />
- < siteMapNode url="~/BasicReporting/DeclarativeParams.aspx"
- title="Declarative Parameters"
- description="Displays a subset of the contents
- of a database table using parameters." />
- < siteMapNode url="~/BasicReporting/ProgrammaticParams.aspx"
- title="Setting Parameter Values"
- description="Shows how to set parameter values
- programmatically." />
- < /siteMapNode>
-
- < siteMapNode title="Filtering Reports"
- url="~/Filtering/Default.aspx"
- description="Samples of Reports that Support Filtering">
- < siteMapNode url="~/Filtering/FilterByDropDownList.aspx"
- title="Filter by Drop-Down List"
- description="Filter results using a drop-down list." />
- < siteMapNode url="~/Filtering/MasterDetailsDetails.aspx"
- title="Master-Details-Details"
- description="Filter results two levels down." />
- < siteMapNode url="~/Filtering/DetailsBySelecting.aspx"
- title="Details of Selected Row"
- description="Show detail results for a selected item in a GridView." />
- < /siteMapNode>
-
- < siteMapNode title="Customized Formatting"
- url="~/CustomFormatting/Default.aspx"
- description="Samples of Reports Whose Formats are Customized">
- < siteMapNode url="~/CustomFormatting/CustomColors.aspx"
- title="Format Colors"
- description="Format the grid's colors based
- on the underlying data." />
- < siteMapNode
- url="~/CustomFormatting/GridViewTemplateField.aspx"
- title="Custom Content in a GridView"
- description="Shows using the TemplateField to
- customize the contents of a field in a GridView." />
- < siteMapNode
- url="~/CustomFormatting/DetailsViewTemplateField.aspx"
- title="Custom Content in a DetailsView"
- description="Shows using the TemplateField to customize
- the contents of a field in a DetailsView." />
- < siteMapNode url="~/CustomFormatting/FormView.aspx"
- title="Custom Content in a FormView"
- description="Illustrates using a FormView for a
- highly customized view." />
- < siteMapNode url="~/CustomFormatting/SummaryDataInFooter.aspx"
- title="Summary Data in Footer"
- description="Display summary data in the grids footer." />
- < /siteMapNode>
-
- < /siteMapNode>
-
- < /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.
- ASP. net mvc Path Selection System Construction
- URL path selection scenario in ASP. net mvc Framework
- URL path selection rules of ASP. net mvc Framework
- ASP. net mvc Framework: Use a strong type class to pass ViewData
- Use ASP. net mvc framework to create an e-commerce website