Digital Colony!

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" />

Labels: , ,

AddThis Social Bookmark Button

3 Comments:

Anonymous Jean Marc SOGALOW said...

The problem with that code is the fact that the meta description and keyword appear not on the head section if you are already using meta from the master page

You can use the solution from JIM

http://www.codeproject.com/useritems/PageTags.asp?df=100&forumid=379932&exp=0&select=1911239

5/13/2007 1:36 PM

Blogger MAS said...

Here is a shorter link for the above comment: tinyurl.com/yt3mpc.

5/13/2007 1:46 PM

Anonymous Anonymous said...

How to add meta keywords when using Master Pages CodeProject file

4/02/2008 7:21 PM

 

Post a Comment

 

Digital Colony Copyright © 1999-2008 XHTML   508
This site uses Blogger, which is not 100% XHTML compliant.
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.