C#SEO

Nested ASP.NET Dynamically add Description and Keywords

I’m have to add description and keywords Meta tag to my html header for search engine to utilize the meta tag analyze my website for ranking. I know that you can make ContentPlaceHolder in the master page of my site, here (http://www.codeproject.com/KB/aspnet/PageTags.aspx) where you can make it build into your master page. But I don’t like it mess up my master page too much, therefore I programmed a public static class to be called and add the Meta tag to the child page on demand. Here I have my MetaGen.cs Class;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.HtmlControls;

/// 
/// Summary description for MetaGen
/// Programmed by Sarin Na Wangkanai
/// Copyright 2008, Alright reserved
/// 
public static class MetaGen
{
	static MetaGen()
	{
	}
    public static HtmlMeta GenDescription(string description)
    {
        //return string.Format("\r\n", description);
        HtmlMeta desc = new HtmlMeta();
        desc.Name = "description";
        desc.Content = description;
        return desc;
    }
    public static HtmlMeta GenKeyword(string keyword)
    {
        //return string.Format("\r\n", keyword);
        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = keyword;
        return keywords;
    }
}

This is how you can access the MetaGen.cs in the child page, simply add the following line to the Page_Load() method.

Page.Header.Controls.Add(SEO.GenDescription("your description"));
Page.Header.Controls.Add(SEO.GenKeyword("keyword1, keyword2"));

This makes it so simple for me.