What’s New in ASP.NET 4.0

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 learn 2 new properties added to Pages Class.

  1. Metkeywords.
  2. 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.

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:

   1: HtmlMeta meta1 = new HtmlMeta();

   2: meta1.Name = "keywords name here";

   3: meta1.Content = "some keywords desctiption here";


   5: HtmlMeta meta2 = new HtmlMeta();

   6: meta2.Name = "keywords name here";

   7: meta2.Content = "some keywords desctiption here";


   9: Page.Header.Controls.Add(meta1);

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

   1: <%@ Page Title="New Features in ASP.NET 4" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"

   2: MetaKeywords="ASP.NET 4, SEO" MetaDescription="This page contains information about ASP.NET 4 and SEO enhancements" %>

In order to retain the older meta tag contents and also use the new ones, just concatenate the two programmatically as shown below:

   1: protected void Page_Load(object sender, EventArgs e)

   2: {

   3:         Page.MetaDescription = Page.MetaDescription + " This page contains information about ASP.NET 4 and SEO enhancements";

   4:         Page.MetaKeywords = Page.MetaKeywords + " ASP.NET 4, SEO";

   5: }


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s