Using SiteMap and MasterPages to set META Tags in ASP. NET and C #

Source: Internet
Author: User
Tags dedicated hosting hosting windows hosting server hosting

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 login factors. having matching terms in your meta tags will rank your page higher, FIG 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 shoshould have something like this:

<? Xml version = "1.0" encoding = "UTF-8"?> <SiteMap xmlns = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">

<SiteMapNode url = "" title = "" description = ">

<SiteMapNode url = "" title = "" description = "/>
<SiteMapNode url = "" title = "" description = "/>

</SiteMapNode>

</SiteMap>

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. 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:


[Click to view full-size]

Next, choose the MasterPage we just created:


[Click to view full-size]

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:

<Form id = "form1" runat = "server">
<Strong> <asp: Literal ID = "lit_PageHeader" runat = "server"/> </strong>
<Div>

<Asp: ContentPlaceHolder id = "ContentPlaceHolder1" runat = "server">

</Asp: ContentPlaceHolder>

</Div>
</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:

<% @ Page Language = "C #" MasterPageFile = "~ /MasterPage. master "AutoEventWireup =" true "CodeFile =" Page1.aspx. cs "Inherits =" Page1 "Title =" Untitled Page "%>

<Asp: Content ID = "Content1" ContentPlaceHolderID = "ContentPlaceHolder1" Runat = "Server">

This is Page1.aspx <br/>
<Asp: HyperLink ID = "HyperLink1" runat = "server" NavigateUrl = "~ /Page2.aspx "Text =" Page 2 "/> |
<Asp: HyperLink ID = "HyperLink2" runat = "server" NavigateUrl = "~ /Page3.aspx "Text =" Page 3 "/>

</Asp: Content>

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:

<? Xml version = "1.0" encoding = "UTF-8"?> <SiteMap xmlns = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">

<SiteMapNode url = "~ /Default. aspx "title =" This is the TITLE of the Default page "PageHeader =" Welcome to the Default Page "description =" This is the META Description tag od the Default Page. "keywords =" keywords, of, the, meta, tag, of, the, default, page ">

<SiteMapNode url = "~ /Page1.aspx "title =" This is the TITLE of Page 1 "PageHeader =" Welcome to Page 1 "description =" This is the META Description of Page 1. "keywords =" keywords, of, the, meta, tag, of, page, one "/>
<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 "/>

</SiteMapNode>

</SiteMap>

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:

Protected void Page_Load (object sender, EventArgs e)
{

If (SiteMap. CurrentNode ["PageHeader"]! = Null)
{

Lit_PageHeader.Text = SiteMap. CurrentNode ["PageHeader"]. ToString ();

}

If (SiteMap. CurrentNode! = Null)
{

Page. Title = SiteMap. CurrentNode. Title;

If (SiteMap. CurrentNode ["keywords"]! = Null)
{

HtmlMeta = new HtmlMeta ();
Meta. Name = "keywords ";
Meta. Content = SiteMap. CurrentNode ["keywords"];
Page. Header. Controls. AddAt (1, meta );

}

If (SiteMap. CurrentNode. Description! = Null)
{

HtmlMeta = new HtmlMeta ();
Meta. Name = "Description ";
Meta. Content = SiteMap. CurrentNode. Description. ToString ();
Page. Header. Controls. AddAt (2, meta );

}

}

}

If you're 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 shoshould be presented with the following in the Title Bar:

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

Also note that the META tags in the source are populated:

<Meta name = "Keywords" content = "keywords, of, the, meta, tag, of, the, default, page"/>
<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.

Here is the original link:

Http://www.programminghelp.com/web-development/asp-net/using-sitemap-and-masterpages-to-set-meta-tags-in-asp-net-and-c/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.