How to Create Meta Tags Programmatically in ASP.NET 2.0

If you have been Developing Web, you may be familiar with the meta tags in an HTML page. The meta tags are used to provides keywords etc in an HTML page.

Now in ASP.NET 2.0, you can add these meta tags programmatically. The HtmlMeta class provides programmatic access to the HTML <meta> element on the server. The HTML <meta> element is a container for data about the rendered page, but not page content itself.

The Name property of HtmlMeta provides the property name and the Content property is used to specify the property value. The Scheme property to specify additional information to user agents on how to interpret the metadata property and the HttpEquiv property in place of the Name property when the resulting metadata property will be retrieved using HTTP.

The following code shows how to add meta tags to a page programmatically.

HtmlMeta metaTag = new HtmlMeta();
metaTag.Name = "Keywords";
metaTag.Content = "Ramani Sandeep, Sandy, Sandeep , Sam";

Add the above created method to Load event of the Page. Now The Result can be seen by viewing dynamically cretaed source of the Page.

Similarly, you can add multiple meta tags to the header of the Page.

You can also add sechema to the Contact.

// Render: <meta name="date" content="2006-03-25" scheme="YYYY-MM-DD" />
meta = new HtmlMeta();
meta.Name = "date";
meta.Content = DateTime.Now.ToString("yyyy-MM-dd");
meta.Scheme = "YYYY-MM-DD";


2 thoughts on “How to Create Meta Tags Programmatically in ASP.NET 2.0

  1. Pingback: Méta-moteur interrogeant des moteurs francophones et moteurs internationaux
  2. Pingback: Windows Vista Business Key

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s