ASP.NET Programatically Add META Keywords and META Description Tags

One important part of any ASP.NET page is adding a META Keywords and META description tag to the HEAD section of the page. Many search engines place significant weight on the presence of these two tags.

There is some disagreement between SEO experts on how much weight is actually put on these tags by search engines like Google, but it is generally accepted that these tags should be present on any page that you wish search engines to index. Unfortunately, this is usually an after thought for many ASP.NET projects.

Of course, the simplest way to add these tags is manually to the HTML part of your ASP.NET page like this:

<meta name="description" content="your description goes here..." />
<meta name="keywords" content="keywords are listed here with a comma" />

But what if you want to add these tags programmatically in the Page_Load event or other code behind method of your page? If you are using ASP.NET 3.5 or lower, you can add the tags like this:

// add meta description towards the top of the HEAD tag on the page
System.Web.UI.HtmlControls.HtmlMeta metaDescription = 
    new System.Web.UI.HtmlControls.HtmlMeta();
metaDescription.Name = "description";
metaDescription.Content = "your description goes here...";
Page.Header.Controls.AddAt(1, metaDescription);

// add meta keywords towards the top of the HEAD tag on the page
System.Web.UI.HtmlControls.HtmlMeta metaKeywords =
    new System.Web.UI.HtmlControls.HtmlMeta();
metaKeywords.Name = "keywords";
metaKeywords.Content = "keywords are listed here with a comma";
Page.Header.Controls.AddAt(1, metaKeywords);

In ASP.NET 4.0 or higher, there is an easier way because of the new built in page methods like this:

Page.MetaDescription = "your description goes here...";
Page.MetaKeywords = "keywords are listed here with a comma";

Hi there, I was wondering

Hi there, I was wondering whether you offered any advertising possibilities on your website? I have a friend who is looking to promote his new website.

You can prepare for your project management exam by spending weeks reading books, or you can simply get the PM PrepCast. This training course was created by a project management expert who has had several years of experience in the field of project management and PMP training.

Yes

Yes, we are looking for advertisers. Please send an email to:

info @ repeatsys.com