joi, 5 iulie 2007

ASP .Net Page.Header with custom meta tags

One of this days a friend of mine shared with me some SEO techniques and one of them was to change the meta tags associated with a product page. So after a little research I found out a way to accomplish this : modify the Header property of ASP .Net page and add several HtmlMeta tags who can hold the data needed to be changed. Each ASP .Net page has a property called Header who is the “hidden” header code of each HTML page. It is available starting with .Net version 2.0 and exposes also the meta tags object collection. Actually, all elements in the header are available in Header.Controls

// Render: <meta name="keywords" content="pharmacy, online pharmacy, home delivery" />
HtmlMeta meta1 = new HtmlMeta();
meta1.Name = "keywords";
meta1.Content = "pharmacy, online pharmacy, home delivery";

// Render: <meta name="verify-v1" content="DmMArCJQq9KV45wvKMwrWASh3R8UWTd7NfBD" />

HtmlMeta meta2 = new HtmlMeta();
meta.Name = "verify-v1";
meta.Content = "DmMArCJQq9KV45wvKMwrWASh3R8UWTd7NfBD";

// Render: <meta name="revisit-after" content="2 days" />

HtmlMeta meta3 = new HtmlMeta();
meta.Name = "revisit-after";
meta.Content = "2 days";

Header.Controls.Add(meta1);
Header.Controls.Add(meta2);
Header.Controls.Add(meta3);