Go to home page mail me! RSS Feed

Programmatically add META tags to your page header

Wednesday, November 28, 2007 10:59 AM

At some point in time, especially when you are doing some serious SEO optimization, you may want to use separate titles, keywords, description and etc. for each page. Thanks, to .NET we can quickly create HtmlMeta controls programmatically and add them to the page header. Here is a quick and dirty snippet.

    private void SetupPageHeader()
    {
        // Page title
        Page.Title = GetGlobalResourceObject("resource","ApplicationWebTitle").ToString();
       
        // Description meta tag
        HtmlMeta descMeta = new HtmlMeta();
        descMeta.Name = "Description";
        descMeta.Content = GetGlobalResourceObject("resource", "MetaDescription").ToString();
        Page.Header.Controls.Add(descMeta);
       
        // Keywords meta tag
        HtmlMeta keysMeta = new HtmlMeta();
        keysMeta.Name = "keywords";
        keysMeta.Content = GetGlobalResourceObject("resource", "MetaKeywords").ToString();
        Page.Header.Controls.Add(keysMeta);
    }

 

kick it on DotNetKicks.com

Your Comments.

No comments posted yet.

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 3 and 5 and type the answer here:

Preview Your Comment.

 
Next entries »