Search This Blog

Thursday, June 10, 2010

Search Engine Optimization (SEO) Enhancement in ASP.NET 4.0


As we all of know Meta description (META description tag) is very significant for SEO point of view. The META Description Tag is a vital part which identifies a page and search engines take this META tag very sincerely. To improve the search relevancy of pages is to make sure you always put relevant “keywords” and “description” <meta> tags within the<head> section of your HTML.

<head runat="server">
    <title>SEO Demo</title>
    <meta name="description" content="Page keywords." />
    <meta name="keywords" content="ASP.NET 4, SEO enhancements." />
</head>
In ASP.NET 4.0, one of the notable enhancements is the addition of two new properties to the Page class:- MetaKeywords and MetaDescription. These put the “keywords” and “description” <meta> tags within the <head> section of the page automatically.

When Useful?

This is particularly useful where your web site are using master-pages – and the section ends up in a .master file. You can now set the new MetaKeywords andMetaDescription properties in the .aspx page and their values will be automatically rendered by the section within the master page.

Using MetaKeywords and MetaDescription properties

You can directly define Meta Keywords and Meta Description through @Page attribute as-

 
Or you can also define the same programmatically in the Page_Load event of the Page class as-

protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.MetaKeywords = "Page key words";
        this.Page.MetaDescription = "Page description";
    }
From both of the above options, the markup gets rendered in the web browser as-

<head>
   <title>SEO Demo</title>
   <meta name="description" content="Page description" />
   <meta name="keywords" content="Page key words" />
</head>
One important point should be noted that if you set the values programmatically, values set declaratively in either the section or via the @Page attribute will be overridden.
If you want to update the meta tag content by keeping the old content intact, use following technique-

protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.MetaKeywords += " - NewPage key words.";
        this.Page.MetaDescription += " - New Page description.";
    }
And now the markup that gets rendered in the web browser is-

<head>
   <title>SEO Demo</title>
   <meta name="description" content="Page description - New Page description."/>
   <meta name="keywords" content="Page key words - NewPage key words." />
</head>

Winding Up

So this is really a nice enhancement in ASP.NET 4.0 that provide us more flexibilities in defining meta tag contents.

1 comment: