Generating search engine optimized page title and meta tags in asp.net. Generating search engine optimized page title and meta tags in asp.net.

The importance of search engine optimized page title and meta tags:

May be you will need to read about seo in general from here before you start

As a asp.net developer it is very important  when you start to build a web site to make it search engine friendly as possible to get the maximum number of free traffic. One of the most important requirement for any webpage to be search engine friendly is to have a unique,unrepeated and very closely related  page title and meta tags. Search engine is giving a a great importance to the text present in the page title and think it the best way to discover what the page is about ,also search engine use your description meta tag( if you used it properly ) to write the page description that appear below the page title in the search result.

When you have a unique description meta tag that is very related to your page content the search engine will use it but if the description meta tag is not unique too short or not related to the page the search engine will choose other text from the page and use it as a description for your page. That automatically chosen text won’t be sexy for the people to click at  which can affect you traffic badly. Also if the page title is repeated or not related to the page you will rank very low for your targeted keywords because there will be other competitive  pages with a better page titles .

Page titles and meta tags generation in asp.net:

As an asp.net developer you should learn how to generate and control page titles and meta tags dynamically.

For any physical asp.net page that has only one version like the “contact us” page or “about the company” page there will be no problem  you just will set the page title and the meta tags statically like if you are preparing a simple html page.Just find the title attribute in the page declaration part of the asp.net aspx page(usually the first line in page ),and set the title property to the value you want and for the meta tags you just add it to the head part of the page like thgis

<META NAME=”description”CONTENT=”your page description”/>

But the problem is in the asp.net pages that  display a different row from the data base every time based on the query string value or something. Also the pages that display contents based on the user country or language.

As i want this article to be easy to understand for the beginner asp.net developer i will explain a very basic example here. We have a scenario that we want to make a details page that display the details of a single product selected on the base of the query string field called “productid”. Sure we will need to generate page title and meta tags dynamically because search engine will see “/productdetails.aspx?productid=1” and “/productdetails.aspx?productid=2” as a totally different pages that must have different page titles,also suppose that the first page is displaying a football and the other page displaying a diving equipment so the page title have to be generated every time the asp.net page load  to be related to the product displayed and rank high when someone search for the  diving eq. for example.

so time for coding

Generating page title and meta tags dynamically explained vb.net code example:

To fulfill the requirement of the scenario described  above  we will add a three fields to the data base “pagetitle”,”descriptionmeta ” and “keyeordmeta” to store the page title and  meta tags for each product these fields should be filled by the seo specialist.

We can make it easier by using product name as the page title and the product description as the page meta description  but i prefer separating what is for humans from what is for search engines because each has it’s  rules.

Prepare a page containing  form view the form view will display one row from the products table on the base of the query string passed with the url.

add two data bound asp.net labels to the asp.net formview with ID’s  “ptitlelbl”, “mdisclbl”  the first id data bounded to the data base field that hold the page title and the other is bounded to the meta description field.

and here is the code behind

Page title:

in the page load event add the following code

Dim ptitle As String
ptitle = DirectCast(FormView1.FindControl(“ptitlelbl”),Label).Text
If String.IsNullOrEmpty(ptitle) Then

Else

Page.Title = ”any thing you want to append”&ptitle
End If

and you done just be sure that there is no static page title tag anywhere (page declaration section,header section of the aspx file or in the master page) not to have unexpected results.

1-we declared a variable to hold the title.

2-we used “formview1.findcontrol” function to find the asp.net label we want  inside the formview(notice form view is naming container so you cant access the control inside it directly like usual ).

3-we check first if the variable is not empty to prevent the ugly looking exception.

4-we used “directcast” because “findcontrol” function return an undefined control so to define the returning object as a label we use “directcast” function.

5-then we set the “title” property of the “page” object to the value we extracted from the data base and append to it any text we want(may be product category for example) .

Meta tags(description ex. ):

also in the page load event add the following vb.net code

Dim ptitle As String
disctext = DirectCast(FormView1.FindControl(“mdisclbl”),Label).Text
If String.IsNullOrEmpty(disctext) Then

Else

Dim headsection As HtmlHead = CType(Me.Header,HtmlHead)
Dim discmetatag As HtmlMeta = New HtmlMeta()
discmetatag.Name = “Description”
discmetatag.Content = “any thing you want to append ,”& disctext
headsection.Controls.Add(discmetatag)
End If

here the code is similar to the code above  except:

1-first we create an instance of our page head section.

2-next we defined a new html meta object.

3-we set its name proberity to “description”(or keyword if you want)

4-then set its content to the text we extracted from the data base.

5-finally we add the meta tag object we created to our page header section

and you are done

some useful tips in generating asp.net page title and description meta tags:

1-it is sometimes important to add different countries or cities to the page title and meta tags because people usually search for service that is located close to them.For example if you have a car rent website may be you should dynamically generate many instances of your  pages  each one is targeted to different cities in your country.believe me it is great tip you should try it if you are making a website that offer a local service.

2-put the most important text in your page in a h1 tag. in our case above it will make a great difference to put the product name asp.net  label in a h1 tag and may be making it bold text also.

3-it is far better to have only h1 tag in each page not more this will keep your page targeted.

IF YOU WANT TO KNOW HOW TO SELECT YOUR KEY WORDS READ THIS

happppy coding and alot of money.

dr A. galal

asp.net developer and seo specialist.

dr.agalal@speakasp.net

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • DotNetKicks
  • Yahoo! Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Technorati
  • Twitter

4,585 comments to Generating search engine optimized page title and meta tags in asp.net.

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>