Sunday, May 31, 2009

Set meta tag in asp.net programmaticaly for seo friendly websites

·

When you are developing SEO friendly websites, the first basic thing for seo is meta tags, as all search engines are looking for these meta tags while querying the database. Here we will allow the user to set the "keywords" and "description" (the two parts of meta tag)and then set the meta tag programmatically.

This is how meta tags are set dynamically:

HtmlMeta mKey = new HtmlMeta();
mKey.Name = "keywords";
mKey.Content = "home, blog";
this.Page.Header.Controls.Add(mKey);


HtmlMeta mdesc = new HtmlMeta();
mdesc.Name = "description";
mdesc.Content ="home page";
this.Page.Header.Controls.Add(mdesc);


after doing that you can view in the "View Source" of the page you have set meta tags under the head section.
<meta name="keywords" content="home,blog" />
<meta name="description" content="home page" />

0 comments: