Click here to Skip to main content
15,896,207 members
Articles / Web Development / ASP.NET

Generate Web Page Titles from your Site Map

Rate me:
Please Sign up or sign in to vote.
3.82/5 (6 votes)
23 Jan 2007CPOL4 min read 40.9K   291   32  
Site maps aren't just for navigation—they contain titles and descriptions of all your web pages. Use those descriptions to title your web pages.
<%  // SiteMapPageTitles.master - Copyright 2007 Kevin P. Rice. All rights reserved. %>
<!-- Tek4 Innovations. http://tek4.com/ Copyright 2007 Kevin P. Rice. All rights reserved. -->
<%@ Master  Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  void Page_Load(Object sender, EventArgs e) {
    // Set page title based upon Site Map Description or Title
    SiteMapNode currentNode = SiteMap.CurrentNode;
    if (currentNode != null) {
      String subTitle = currentNode.Description;
      if (subTitle.Length == 0) subTitle = currentNode.Title;
      if (subTitle.Length !=0 && subTitle != "Tek4.com") 
	    Page.Title += "\u2014" + Server.HtmlEncode(subTitle);
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">

<head runat="server">
  <title>Tek4 Innovations</title>
</head>

<body>
<asp:SiteMapPath id="SiteMapPath" runat="server"/>

<asp:contentplaceholder id="Content" runat="server">
  <h1>SiteMapPageTitles.master Default Content</h1>
</asp:contentplaceholder>

</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Kevin Rice is a firefighter for a major Southern California fire department. When not working, he enjoys web programming, administration, riding dirt-bikes (Visit SLORider.com) or building anything electronic.

Comments and Discussions