Add META keywords and Description in ASP.NET

Here is the syntax for programmatically adding META tags to an ASP.NET 2.0 page.

HtmlMeta metaDesc = new HtmlMeta();
metaDesc.Name = "description";
metaDesc.Content = "Tips on roasting coffee at home";
Page.Header.Controls.Add(metaDesc);

HtmlMeta metaKey = new HtmlMeta();
metaKey.Name = "keywords";
metaKey.Content = "roast, coffee, home, tips";
Page.Header.Controls.Add(metaKey);

ASP.NET will render the above code to valid XHTML META tags.

<meta name="description" content="Tips on roasting coffee at home" />
<meta name="keywords" content="roast, coffee, home, tips" />
This entry was posted in ASP.NET and tagged . Bookmark the permalink.

Comments are closed.