Using the SiteMap for SEO Purposes in ASP.NET 3.5 and C#
Introduction
Especially since the introduction of Web 2.0, a new emphasis has been made on SEO (Search Engine Optimization) for our web pages. Google, amongst others, have managed to organize the world's data so well, that it is becoming more and more important to adhere to such organization techniques to gain the traffic your web site deserves.
In this article we will look at one of the ways we can use the SiteMap in ASP.NET to organize our Web Page more efficiently, and also make it easier for us to update. We will be creating a SiteMap file, which is written in XML, to define our meta Title, Description, Keywords tags as well as page Headers for each of our Web Pages depending upon their location.
What we will learn in this article:
- How to utilize an ASP.NET SiteMap to harness the power of SEO
- How to make it easier for us to maintain a multi-page Web Site using a SiteMap
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
Getting Started
The major search engines rank a page against serach results based upon many factors. Having matching terms in your meta tags will rank your page higher, particularly in Title, Description and Keywords. However, when maintaining larger sites, this can be difficult to keep organized and a hefty chore to maintain and update. However, we will show how we can make it a little easier using the SiteMap.
To begin, start a new Web Site project in Visual Studio.NET - in this example, we will be using 2008, but 2005 will work just fine.
Once open, right-click your project in the Solution Explorer and choose Add New Item.. SiteMap. Leave the name as Web.sitemap and click Ok. You should have something like this:
<siteMapNode url="" title="" description="" />
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
This is where we start off. But first, let's create some pages to work with. First, let's add a MasterPage: right-click your project and choose Add New Item.. MasterPage. Leave the name as MasterPage.master and then delete the Default.aspx that was added when you created the project.
Now we can add a new Web Form, making sure we check the box to select a Master Page:
Next, choose the MasterPage we just created:
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
Our next step is to design our MasterPage. For the purpose of this tutorial, we will simply add a Literal control as a placeholder for the page header:
<strong><asp:Literal ID="lit_PageHeader" runat="server" /></strong>
<div>
</asp:ContentPlaceHolder>
</form>
We will also add three more Web Forms to our Project, namely Page1.aspx, Page2.aspx and Page3.aspx and we will identify them in the body, and link to all other pages, like so:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Page2.aspx" Text="Page 2" /> |
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Page3.aspx" Text="Page 3" />
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
We make sure that we check MasterPage for each of our Web Forms.
The Literal control in our MasterPage is going to display the page header that we specify for each page in the SiteMap. Let's go ahead and begin our SiteMap. It will have somewhat of a hierarchical structure like so:
<siteMapNode url="~/Page2.aspx" title="This is the TITLE of Page 2" PageHeader="Welcome to Page 2" description="This is the META Description of Page 2." keywords="keywords, of, the, meta, tag, of, page, two" />
<siteMapNode url="~/Page3.aspx" title="This is the TITLE of Page 3" PageHeader="Welcome to Page 3" description="This is the META Description of Page 3." keywords="keywords, of, the, meta, tag, of, page, three" />
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
Notice our attributes for each page in our project. We will be using title for the Meta Title tag, PageHeader for our Literal control, description for the Meta description tag, and keywords for the Meta keywords tag.
To implement this, we will add code-behind to the Master Page:
{
{
if (SiteMap.CurrentNode != null)
{
if (SiteMap.CurrentNode["keywords"] != null)
{
meta.Name = "keywords";
meta.Content = SiteMap.CurrentNode["keywords"];
Page.Header.Controls.AddAt(1,meta);
if (SiteMap.CurrentNode.Description != null)
{
meta.Name = "Description";
meta.Content = SiteMap.CurrentNode.Description.ToString();
Page.Header.Controls.AddAt(2,meta);
If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!
Now when we run Default.aspx we should be presented with the following in the Title Bar:

And we should also be presented with the Page Header from the Web.sitemap:

Also note that the META tags in the source are populated:
<meta name="Description" content="This is the META Description tag od the Default Page." />
What we have Learned
We have learned that we can use the SiteMap to easily managed and update our Meta tags for each of our pages within our site.
Attachments




Leave a Comment
#1 Danny117
Posted By: Danny117 | 1.29.2009 at 6:05 PM
I didn't know I could just add attributes to the sitemap and the sitemap.currentnode I'm going to use this one way or another.
#2 Shafaqat
Posted By: Shafaqat | 1.29.2009 at 10:35 PM
Nice article man, but i am confused that, is URL Rewriting something different?
#3 Norbert
Posted By: Norbert | 1.30.2009 at 4:31 AM
The way you mixed ads through your article is down right awful. It puts me off. I don't think I'm going to visit this site often. I don't think this will make many other people make a return visit --> bye,bye ad profits.
#4 Johan
Posted By: Johan | 1.30.2009 at 10:40 AM
Have to agree on the awful ads in the text! Really puts me off coming back to this blog!
#5 rtpHarry
Posted By: rtpHarry | 1.30.2009 at 7:27 PM
Hey did you access the data in two different ways just to illustrate a point or was there a reason to use on over the other? I am talking about:
meta.Content = SiteMap.CurrentNode["keywords"];
meta.Content = SiteMap.CurrentNode.Description.ToString();
Also I have to agree that the way the adverts are blended in to the copy doesnt work for me. You should apply some sort of visual style for it. I know this way around you are getting people to read your adverts but it is creating a negative association with the product as its annoying to have to switch gears when you are learning something new. Just keep them nearby and let peoples curiosity draw them to your ad partners websites!
#6 Alfes
Posted By: Alfes | 2.04.2009 at 10:45 AM
Easy step by step tutorial to understand sitemap.
www.asp.net/.../video-192.aspx
I also do appreciate your effort to dynamically add the meta tag and title to every page. I like it.
Please do not put ads in the description.
#7 Dulwan Baddewithana
Posted By: Dulwan Baddewithana | 4.08.2009 at 9:39 PM
Hmm..a nice one again but a little bit confused
#8 zunisun26
Posted By: zunisun26 | 5.23.2009 at 3:48 PM
yes, yes, you bad bad ad test, html writers
#9 coolnik999
Posted By: coolnik999 | 7.31.2009 at 1:02 PM
damn good ..........
#10 Carl
Posted By: Carl | 8.29.2009 at 9:22 AM
Completely agree with other posters, great article but terrible ad placement. Please put ads in a side box or something.
#11 Rate Your Doctor
Posted By: Rate Your Doctor | 10.02.2009 at 10:39 AM
Even when optimizing websites built on asp.net sometimes it may be be as search engine friendly
#12 Rate Your Doctor
Posted By: Rate Your Doctor | 10.02.2009 at 10:39 AM
Even when optimizing websites built on asp.net sometimes it may be be as search engine friendly
#13 Muhammad Imran
Posted By: Muhammad Imran | 10.14.2009 at 2:53 AM
Very nice article.
Thanks
#14 Online Marketing degree
Posted By: Online Marketing degree | 10.15.2009 at 5:54 AM
In this article, we will be exploring the new addition to the .NET Framework: Microsoft Chart Controls, and how we can implement full-blown graphs and charts into our Web Applications using only ASP.NET - no need for third party plugins.
#15 Animation degree
Posted By: Animation degree | 10.15.2009 at 5:54 AM
Jessica, you are the prettiest woman in the world and you are so talented. I love you! Keep doing your thing.
#16 Multimedia degree
Posted By: Multimedia degree | 10.15.2009 at 5:54 AM
Does anyone know if and when Jessica will be coming to Florida? Really want to see her live but haven't had a chance to yet.
#17 Finance degree
Posted By: Finance degree | 10.15.2009 at 5:54 AM
The prerequisites for this article are to download and install MSChart and the add-on for Visual Studio. This tutorial is written with Visual Studio.NET 2008 and ASP.NET 3.5 (Please note, MSChart is not compatible with .NET versions below 3.5
#18 Online management degree
Posted By: Online management degree | 10.15.2009 at 5:55 AM
Another great place to go for MSChart info is http://code.msdn.microsoft.com/mschart, which have code samples of different kinds of graphs and charts.
#19 Tiffany Rings
Posted By: Tiffany Rings | 10.23.2009 at 7:37 AM
i like
#20 christmas gift ideas for women
Posted By: christmas gift ideas for women | 10.27.2009 at 8:33 PM
This outlines what I have offered previously. Well done.
#21 Free SMS
Posted By: Free SMS | 10.28.2009 at 7:36 PM
Nice article.
#22 buy darkfall gold
Posted By: buy darkfall gold | 11.05.2009 at 12:50 AM
I don't think I'm going to visit this site often. I don't think this will make many other people make a return visit --> bye,bye ad profits.
#23 domuz gribi
Posted By: domuz gribi | 11.09.2009 at 1:49 PM
thanks for info. <a href="http://www.domuzgribi.in"> domuz gribi </a></p>
<p><a href="http://www.domuzgribi.in"> domuz gribi belirtileri </a>
#24 darkfall gold
Posted By: darkfall gold | 11.14.2009 at 2:33 AM
Have to agree on the awful ads in the text! Really puts me off coming back to this blog!
#25 accredited online colleges
Posted By: accredited online colleges | 11.24.2009 at 8:33 AM
Very useful information, thanks!
#26 free online games
Posted By: free online games | 11.24.2009 at 10:59 PM
Have to agree on the awful ads in the text! Really puts me off coming back to this blog!
#27 Alcohol Rehab Program salt lake city Utah
Posted By: Alcohol Rehab Program salt lake city Utah | 12.10.2009 at 5:43 PM
The below tutorial demonstrates how to create and use the new ASP.NET Master Pages and Site Navigation features within VS 2005 Web Application Projects. Please make sure that you have already completed Tutorial 4:
#28 manali K
Posted By: manali K | 12.15.2009 at 6:51 AM
Realy useful
#29 3rbsc.com
Posted By: 3rbsc.com | 12.18.2009 at 7:50 AM
good topic
#30 Index
Posted By: Index | 12.20.2009 at 7:32 PM
good article for SEO.
#31 dungeon fighter gold
Posted By: dungeon fighter gold | 12.23.2009 at 12:59 AM
nice but a little bit confused
#32 darkfall gold
Posted By: darkfall gold | 12.24.2009 at 2:46 AM
We can put forward a contract that says we want something for nothing, but at the end of the day that’s just not going to wor
#33 firmalar
Posted By: firmalar | 12.24.2009 at 1:50 PM
tanks for info
#34 links of london
Posted By: links of london | 12.26.2009 at 12:25 AM
i like
#35 Free SMS
Posted By: Free SMS | 12.26.2009 at 3:38 PM
hey nice articel.. very nice information
#36 Free SMS ohne Anmeldung
Posted By: Free SMS ohne Anmeldung | 12.26.2009 at 3:39 PM
Nice Artikel.. ::)
#37 Watch Anime Online
Posted By: Watch Anime Online | 1.01.2010 at 11:28 PM
The way you mixed ads through your article is down right awful. It puts me off. I don't think I'm going to visit this site often. I don't think this will make many other people make a return visit --> bye,bye ad profits.
#38 dungeon fighter online gold
Posted By: dungeon fighter online gold | 1.06.2010 at 4:02 AM
Now many people like to play pc online game,it is wonderful, If you play runescape online, you buy<a href=\"http://www.gamemammy.com/runescape\">runescape money</a>,so you can improve your level.but someone play darkfall online,he think he need many items to play because is exciting <a href=\"http://www.idarkfallgold.com\">darkfall gold</a>.and now here i am play dungeon fighter online ,i buy <a href=\"http://www.dfobaby.com\">Dungeon Fighter gold</a>.
#39 tiensshop
Posted By: tiensshop | 1.09.2010 at 3:22 AM
Hey you have a great article but terrible ad placement. Please put ads in a side box for easy understanding.
#40 canada pharmacy
Posted By: canada pharmacy | 1.10.2010 at 2:42 AM
As present, the only worthy competition Viagra has is a particular species of jellyfish which give rise to a prolonged erection when it stings a man. It is commonly known as the Irukandji Syndrome. Apart from the erection side effects of the sting include severe pain, a potentially fatal increase in blood pressure and severe cerebral hemorrhaging.
#41 flowers phoenix
Posted By: flowers phoenix | 1.16.2010 at 1:12 PM
this is indeed great work
#42 How to play craps online games
Posted By: How to play craps online games | 1.20.2010 at 4:35 AM
Thanks a lot. This is a site which has to be bookmarked, you have great articles and wonderful post. what an inspiration.Ant beginner will find excellent teachings here.Beautiful pictures and nice posts. you are doing an excellent job.
#43 Web Development Services
Posted By: Web Development Services | 1.29.2010 at 5:00 AM
This is a damn good post for me!!! Thanks for sharing this post.
#44 archer season 1 episode 5
Posted By: archer season 1 episode 5 | 2.08.2010 at 6:39 AM
The way you mixed ads through your article is down right awful. It puts me off. I don't think I'm going to visit this site often. I don't think this will make many other people make a return visit --> bye,bye ad profits.
#45 the real housewives of orange county season 5 episode 11
Posted By: the real housewives of orange county season 5 episode 11 | 2.08.2010 at 6:40 AM
I have to agree that the way the adverts are blended in to the copy doesnt work for me. You should apply some sort of visual style for it. I know this way around you are getting people to read your adverts but it is creating a negative association with the product as its annoying to have to switch gears when you are learning something new.
#46 burn notice season 3 episode 12
Posted By: burn notice season 3 episode 12 | 2.08.2010 at 6:41 AM
Easy step by step tutorial to understand sitemap.
#47 iorien
Posted By: iorien | 2.16.2010 at 11:59 AM
And what should we do if we have two sitemap providers in our web.config? How can I change provider to make the meta title and meta description work with the apropiate provider?
Thank's
#48 tadalafil
Posted By: tadalafil | 2.17.2010 at 2:51 PM
I decided to blend the management and generation of the meta tags and sitemap into one set of tools that could be easily implemented into any asp.net site.
#49 aion kinah
Posted By: aion kinah | 2.22.2010 at 2:04 AM
Realy useful
#50 darkfall gold
Posted By: darkfall gold | 2.23.2010 at 3:09 AM
Very useful information, thanks!
#51 dfo gold
Posted By: dfo gold | 2.23.2010 at 3:10 AM
Nice article man
#52 alabama web design
Posted By: alabama web design | 3.01.2010 at 3:47 AM
If you have been programming Web, you may be familiar with the meta tags in an HTML page. The meta tags are used to provides keywords etc in an HTML page. Now in ASP.NET 2.0, you can add these meta tags programmatically. The HtmlMeta class provides programmatic access to the HTML <meta> element on the server. The HTML <meta> element is a container for data about the rendered page, but not page content itself. The Name property of HtmlMeta provides the property name and the Content property is used to specify the property value. The Scheme property to specify additional information to user agents on how to interpret the metadata property and the HttpEquiv property in place of the Name property when the resulting metadata property will be retrieved using HTTP. The following code shows how to add meta tags to a page programmatically. private void CreateMetaTags() { HtmlMeta hm = new HtmlMeta(); HtmlHead head = (HtmlHead)Page.Header; hm.Name = "Keywords"; hm.Content = "C#, Csharp, C-sharp, .NET"; head.Controls.Add(hm); } Similarly, you can add multiple meta tags to the header
#53 dfs
Posted By: dfs | 3.04.2010 at 12:16 AM
they are very good and useful!!!
<a href="http://www.uggsoutletstores.org"> ugg outlet</a>
[url=http://www.uggsoutletstores.org] ugg outlet[/url]
ugg outlet www.uggsoutletstores.org
#54 moda blogu
Posted By: moda blogu | 3.07.2010 at 3:30 AM
I found your website from lycos and it is amazing. Thank you for providing such an incredible article!!!
#55 ppsdtw
Posted By: ppsdtw | 3.11.2010 at 2:12 AM
I know, We would say with still redden family link of london. Because jewelries, we could be better to go notion clothes with a will that everything is OK for me <a href="http://www.linksoflondon.in/links-of-london-tell-you-different-kinds-of-gift-ideas/">links of london</a> excluding relations of london! Want