Click here to Skip to main content
11,705,098 members (46,731 online)
Click here to Skip to main content

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

, 9 Jun 2010 CPOL 23K 31
Rate this:
Please Sign up or sign in to vote.
This article explains the MetaKeywords and MetaDescription properties related to SEO enhancement in ASP.NET 4.0.

Table of Contents

Introduction

As we all know, Meta description (META description tag) is very significant from the 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 is it Useful?

This is particularly useful where your websites are using master-pages – and the section ends up in a .master file. You can now set the new MetaKeywords and MetaDescription 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:

<%@ Page
    Title="SEO Demo"
    Language="C#"
    MasterPageFile="~/MasterPage.master"
    AutoEventWireup="true"
    CodeFile="Default.aspx.cs"
    Inherits="_Default"
    MetaKeywords="Page key words"
    MetaDescription="Page description"
%> 

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 the 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 provides us more flexibilities in defining meta tag contents.

History

  • 9th June, 2010 -- Article updated (Added table of contents)
  • 9th June, 2010 -- Original version posted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Samir NIGAM
Technical Lead Infogain India Pvt Ltd
India India

Samir NIGAM is a Microsoft Certified Professional. He is an insightful IT professional with results-driven comprehensive technical skill having rich, hands-on work experience n web-based applications using ASP.NET, C#, AJAX, Web Service, WCF, jQuery, Microsoft Enterprise Library , LINQ, MS Entity Framework, nHibernate, MS SQL Server & SSRS.

He has earned his master degree (MCA) from U.P. Technical University, Lucknow, INDIA, his post graduate dipoma (PGDCA ) from Institute of Engineering and Rural Technology, Allahabad, INDIA and his bachelor degree (BSc - Mathematics) from University of Allahabad, Allahabad, INDIA.

He has good knowledge of Object Oriented Programming, n-Tier Architecture, SOLID Principle, and Algorithm Analysis & Design as well as good command over cross-browser client side programming using JavaScript & jQuery,.

Awards:


You may also be interested in...

Comments and Discussions

 
QuestionAmazing Information! Pin
Misha Infotech29-Apr-15 21:27
memberMisha Infotech29-Apr-15 21:27 
QuestionSEO optimization Pin
Member 114211692-Feb-15 5:39
memberMember 114211692-Feb-15 5:39 
Questioncan i use it for my website Pin
ductri30-Jan-12 22:48
memberductri30-Jan-12 22:48 
GeneralMy vote of 1 Pin
Miroslav Sommer23-Nov-10 22:29
memberMiroslav Sommer23-Nov-10 22:29 
GeneralMy vote of 4 Pin
lovejun17-Aug-10 14:21
memberlovejun17-Aug-10 14:21 
GeneralMy vote of 2 Pin
archippus15-Jun-10 3:30
memberarchippus15-Jun-10 3:30 
GeneralGreat article Pin
Santiago Santos Cortizo14-Jun-10 20:32
memberSantiago Santos Cortizo14-Jun-10 20:32 
GeneralGood One Pin
Viral Upadhyay9-Jun-10 2:43
memberViral Upadhyay9-Jun-10 2:43 
GeneralRe: Good One Pin
Samir NIGAM9-Jun-10 3:08
memberSamir NIGAM9-Jun-10 3:08 
Generalmore info Pin
Mattia Baldinger9-Jun-10 1:17
memberMattia Baldinger9-Jun-10 1:17 
GeneralRe: more info Pin
Samir NIGAM9-Jun-10 3:15
memberSamir NIGAM9-Jun-10 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 9 Jun 2010
Article Copyright 2010 by Samir NIGAM
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid