Site Navigation with Web Forms Controls
ASP.NET Web Forms includes a site-map-driven navigation system built around a single XML file, typically named Web.sitemap, that describes the hierarchical structure of a site's pages as nested siteMapNode elements with title, description, and url attributes. Three controls consume this structure without any manual wiring: SiteMapPath renders a breadcrumb trail from the site root to the current page, Menu renders a static or dynamic drop-down navigation menu, and TreeView renders an expandable hierarchical tree, and all three can bind either to the default SiteMapDataSource or to any other hierarchical data source.
Cricket analogy: Web.sitemap describing a nested page hierarchy is like an ICC tournament bracket file listing groups, then knockout rounds, then the final, with every match node just waiting to be rendered as a bracket graphic.
SiteMapPath, Menu, and TreeView
SiteMapPath needs almost no configuration beyond dropping the control onto a page — it automatically walks up from the current page's node in Web.sitemap to the root and renders each ancestor as a clickable link separated by a configurable PathSeparator. Menu and TreeView both support binding to a SiteMapDataSource via DataSourceID, and each offers StaticDisplayLevels or ExpandDepth-style properties to control how much of the hierarchy renders immediately versus on interaction, along with template properties like StaticMenuItemStyle or NodeStyle for full visual customization of each level.
Cricket analogy: SiteMapPath automatically walking up to the root is like a scorecard app auto-generating the breadcrumb 'ICC World Cup > Semi-Final > India vs Australia' without a developer hardcoding each stage.
<!-- 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">
<siteMapNode url="~/Products/Default.aspx" title="Products">
<siteMapNode url="~/Products/Electronics.aspx" title="Electronics" />
<siteMapNode url="~/Products/Books.aspx" title="Books" />
</siteMapNode>
<siteMapNode url="~/About.aspx" title="About Us" />
</siteMapNode>
</siteMap>
<!-- On any content page -->
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" > " />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ExpandDepth="1" />
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"
Orientation="Horizontal" StaticDisplayLevels="1" />Programmatic Navigation
Beyond declarative navigation controls, code-behind moves users between pages with Response.Redirect(url), which sends an HTTP 302 to the browser and starts a brand-new request/response cycle (losing the current page's state unless explicitly passed via query string or Session), or with Server.Transfer(url), which switches execution to another page entirely on the server without a round trip to the browser, preserving the current request's Form and QueryString collections but leaving the browser's address bar unchanged, which can be confusing for bookmarking. Server.Transfer also does not run through IIS request filtering the way a fresh Redirect request would, so it's generally reserved for same-application forwarding after already-completed permission checks, not for cross-application or cross-domain jumps.
Cricket analogy: Response.Redirect is like a broadcast fully cutting to a different channel's live feed, with the viewer's remote (browser address bar) now showing that new channel, while Server.Transfer is like an internal studio switch to a different camera feed without the viewer's channel display ever changing.
Server.Transfer preserves the current Form and QueryString collections but does not update the browser's URL, which breaks bookmarking and can surprise users who expect the address bar to reflect where they actually landed. It also skips any URL-based security or logging that depends on a fresh request hitting IIS, so it should only be used for trusted, same-application forwarding after authorization has already been checked.
- Web.sitemap defines a site's page hierarchy as nested siteMapNode elements consumed by navigation controls.
- SiteMapPath automatically renders a breadcrumb trail from the site root to the current page.
- Menu and TreeView bind to SiteMapDataSource (or other hierarchical sources) for drop-down and expandable tree navigation.
- StaticDisplayLevels and ExpandDepth control how much of the hierarchy renders immediately versus on interaction.
- Response.Redirect issues a browser round trip (HTTP 302) and updates the address bar; state must be passed explicitly.
- Server.Transfer switches execution server-side without a round trip, preserving Form/QueryString but not updating the URL.
- Server.Transfer is best reserved for same-application forwarding after authorization checks have already passed.
Practice what you learned
1. What file typically defines the hierarchical structure consumed by ASP.NET's site-map navigation controls?
2. Which control automatically renders a breadcrumb trail from the site root to the current page?
3. What is the key difference between Response.Redirect and Server.Transfer?
4. Which property controls how many levels of a Menu control's hierarchy are displayed without requiring user interaction?
5. Why should Server.Transfer generally be avoided for cross-application navigation?
Was this page helpful?
You May Also Like
Master Pages
Understand how ASP.NET Web Forms master pages provide a shared, reusable layout that individual content pages fill in via ContentPlaceHolder regions.
User Controls
Learn how ASP.NET Web Forms user controls (.ascx) let you package reusable markup and code-behind logic into components shared across pages.
The Postback Model
How ASP.NET Web Forms simulates a stateful, event-driven experience over stateless HTTP through postbacks, __doPostBack, and cross-page posting.
Web Forms Best Practices
Practical guidelines for writing maintainable, secure, and performant ASP.NET Web Forms applications, from ViewState discipline to layered code organization.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics