What's New in ASP.NET 4.0 – SEO Enhancements with MetaKeywords and MetaDescription properties

Posted by: Suprotim Agarwal , on 3/12/2010, in Category ASP.NET
Views: 62517
Abstract: In this article, we will take an overview of the two new properties added to the Page class in ASP.NET 4.0 – MetaKeywords and MetaDescription.
What's New in ASP.NET 4.0 – SEO Enhancements with MetaKeywords and MetaDescription properties
 
With the ASP.NET 4.0 release round the corner, I thought of starting an article series that covers the new features introduced in ASP.NET 4.0, one at a time. This article is Part I of this multi-part series. In this article, we will take an overview of the two new properties added to the Page class in ASP.NET 4.0 – MetaKeywords and MetaDescription.
The MetaDescription is important from an SEO perspective. The META Description Tag is an integral part which identifies a page and irrespective of the contrary belief, I think search engines take this meta tag seriously. You should too!

 

Now in ASP.NET 2.0/3.5, you could use the HTMLMeta class to define HTML <meta> elements for your page as shown below:
HtmlMeta meta1 = new HtmlMeta();
meta1.Name = "keywords";
meta1.Content = "some keywords";
 
HtmlMeta meta2 = new HtmlMeta();
meta2.Name = "description";
meta2.Content = "add meta description";
 
Page.Header.Controls.Add(meta1);
Page.Header.Controls.Add(meta2);
Too much code!
However in ASP.NET 4.0, you now have two new properties added to the Page class – MetaKeywords and MetaDescription.
MetaDescription
So you can now declaratively define MetaKeywords and Description directly in your Page as shown below:
<%@ Page Title="New Features in ASP.NET 4" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
MetaKeywords="ASP.NET 4, SEO" MetaDescription="This page contains information about ASP.NET 4 and SEO enhancements" %>
 
 The markup gets rendered in the browser as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>
New Features in ASP.NET 4
</title><link href="Styles/Site.css" rel="stylesheet" type="text/css" />
<meta name="description" content="This page contains information about ASP.NET 4 and SEO enhancements" />
<meta name="keywords" content="ASP.NET 4, SEO" />
</head>
...
You can also programmatically define the MetaKeywords and MetaDescription properties by reading them from a database or manually declaring them on the Page object as shown here:
C#
protected void Page_Load(object sender, EventArgs e)
{
        Page.MetaDescription = "This page contains information about ASP.NET 4 and SEO enhancements";
        Page.MetaKeywords = "ASP.NET 4, SEO";
}
 
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      Page.MetaDescription = "This page contains information about ASP.NET 4 and SEO enhancements"
      Page.MetaKeywords = "ASP.NET 4, SEO"
End Sub
Note: If these meta tags are already declared on your page, then they will be overwritten when you follow the techniques shown above. For example, if your page already has existing meta tags..
<head runat="server">
    <title></title>
    <meta name="description" content="sample content" />
    <meta name="keywords" content="k1, k2" />
 
..and if you explicitly set the MetaDescription and MetaKeywords properties through the Page object, then these properties will overwrite the Meta tag contents already present on the page.
In order to retain the older meta tag contents and also use the new ones, just concatenate the two programmatically as shown below:
C#
protected void Page_Load(object sender, EventArgs e)
{
        Page.MetaDescription = Page.MetaDescription + " This page contains information about ASP.NET 4 and SEO enhancements";
        Page.MetaKeywords = Page.MetaKeywords + " ASP.NET 4, SEO";
}
 
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      Page.MetaDescription = Page.MetaDescription & " This page contains information about ASP.NET 4 and SEO enhancements"
      Page.MetaKeywords = Page.MetaKeywords & " ASP.NET 4, SEO"
End Sub
The Meta tags now get rendered in the browser as shown below, concatenating both the older and new values:
<head><title>
New Features in ASP.NET 4
</title>
<meta name="description" content="sample content This page contains information about ASP.NET 4 and SEO enhancements" />
<meta name="keywords" content="k1, k2 ASP.NET 4, SEO" /><link href="Styles/Site.css" rel="stylesheet" type="text/css" />
</head>
 
In the upcoming articles, we will continue exploring new features of ASP.NET 4.0. I hope you liked the article and I thank you for viewing it.
If you liked the article,  Subscribe to the RSS Feed or Subscribe Via Email

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for Sixteen consecutive years. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.

Get in touch with him on Twitter @suprotimagarwal or at LinkedIn



Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Praveen on Friday, March 12, 2010 3:33 PM
Good addition. However, in a typical web business setup, you'd have your metas read from a repository or an XML file which is maintained by the SEO guy or the biz people. A helper method on your PageBase would usually take care of applying the Metas to the page in question.

Nice post nonetheless!
Comment posted by Welsh on Saturday, March 13, 2010 9:36 AM
Dude I am looking forward to this series. I love your writing. You make it look so simple
Comment posted by Jiteen on Friday, March 26, 2010 2:20 AM
This feature is already present in ASP.NET 3.5. It's not new. Please confirm.
Comment posted by Suprotim Agarwal on Saturday, March 27, 2010 11:44 PM
Jiteen: The article clearly explains how we could do it in ASP.NET 3.5 and how it is done in 4.0 with the addition of new properties
Comment posted by Vishal on Wednesday, March 31, 2010 4:35 AM
The Microsoft .NET Framework 4 coming up with many features for helping developers to create applications faster than ever and fully compatible with the older versions of .NET Framework.

For more details view below URL:

http://blog.conceptinfoway.net/post/2010/03/31/New-Features-in-NET-Framework-40.aspx
Comment posted by ipomz on Monday, April 26, 2010 3:35 AM
thank
Comment posted by Nikunj Dhawan on Monday, May 24, 2010 9:29 AM
Yes... good to know.... can these be data binded?
Comment posted by single women on Saturday, October 9, 2010 6:43 AM
I cannot WAIT to read more of this. I mean, you just know so much about this. So much of it Ive never even thought of. You sure did put a new twist on something that Ive heard so much about. I dont believe Ive actually read anything that does this subject as good justice as you just did.
Comment posted by Justin on Friday, May 13, 2011 6:25 AM
Hello!!

This was a great post  and very helpful as well.

Thanks
Justin
<a href="http://www.waterdamagelocal.com">Flood Damage</a>
Comment posted by Greg on Tuesday, May 17, 2011 6:56 PM
Useful info, i am actually in the middle of a vb.net project using vb/vs 2010 and silverlight... Helpful! <a href="http://www.floodtechs.com">water damage restoration</a>
Comment posted by Joshone on Monday, March 5, 2012 11:47 PM
Your content is very useful. Thank you so much for providing plenty of useful content. I have bookmarked your site and will be without doubt coming back. Once again, I appreciate all your work and also providing a lot vital tricks for your readers.
Comment posted by SEO Company India on Monday, March 12, 2012 7:06 AM
Excellent site, keep up the good work. I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog.
<p><a href="http://www.techmagnate.com/seo-company-india.html">SEO Company India</a></p>