Search code examples
c#asp.net.netwebformsweb.sitemap

How to get current page title from sitemap file?


In my master page (.aspx file) I have this <div> to display the page title:

<div class="header">
<h1> PAGE TITLE GOES HERE </h1>
</div>

I also have a Web.sitemap file that holds the details of some pages (not all of pages in my applications)

What should I put in between <h1></h1> to let the master page dynamically display page title of current page and also if the current page is not in sitemap or doesnt have title then put some default string like "DEFAULT TITLE"


Solution

  • If you want to be lazy about it and don't care about code in your .aspx file, simply:

    <h1><%= SiteMap.CurrentNode != null ? SiteMap.CurrentNode.Title : "not in sitemap!" %></h1>