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.
-
Metkeywords.
-
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";
4:
5: HtmlMeta meta2 = new HtmlMeta();
6: meta2.Name = "keywords name here";
7: meta2.Content = "some keywords desctiption here";
8:
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: }