Dynamically create Meta Description using Asp.Net

← PrevNext →

HTML meta description allows us to describe web pages with short and sometimes elaborated details. Descriptions written inside the <meta> tag, must always to specific and are often limited to very few characters. Using Asp.Net, we can easily create “meta” descriptions dynamically, through code behind procedures, describing the contents of the page.

Not just limited characters (as defined by Google and other search engines) but also similar descriptions (duplicate) must not be repeated in other pages. Though meta description do not directly effects the web ranking of a site, but lengthy and duplicate meta descriptions does not go well in the eyes of the search engine.

Search engines do not need lengthy descriptions to understand the contents of a web page. All it needs is a more specific and a short description (about 150 to 160 characters) describing the contents of the page.

These meta descriptions can be controlled and created dynamically using Asp.Net from code behind.

HTML meta description

Typically a meta description is written inside a meta tag, inside the HEAD tag in a web page. This is where you describe the page with a small summary of the contents of the page.

    <meta name="description" content="Article on HTML meta description" />

The content attribute has the summary and in the above case, is been written while page declaration.

Now imagine a scenario where you have dynamic contents and the descriptions must be created dynamically too. The source of these contents can be anything, extracted from a database or a file. All we want is to display it to our web pages, dynamically.

Dynamic “meta” description

Code Behind (C#)
protected void form1_Load(object sender, System.EventArgs e)
	HtmlMeta metaDescription = new HtmlMeta();

	metaDescription.Name = "description";
	metaDescription.Content = "Article on HTML meta description";
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load

    Dim metaDescription As New HtmlMeta

    metaDescription.Name = "description"
    metaDescription.Content = "Article on HTML meta description"
End Sub

In the above codes, the HtmlMeta class will allow a developer to access the HTML meta tag programmatically. Property Name has the value, description and the property Content has the summary to describe the page. Finally add the Name and Content properties to the page header using the Header property of the HtmlHeader class.


As I have mentioned earlier in this article that the meta tags are written inside the <head> tag, it is important to remember that the <head> tag should have the attribute runat="server" defined in the page declaration itself. Else, it will throw an error saying, Object reference not set to an instance of an object.

<head runat="server">


Dynamically created meta descriptions are useful when the contents of the web pages are extracted from another source and if the web page has paginations. Pagination typically refers to a process of dividing contents into many web pages, using “next”, “previous” and “number” links.

Sometimes we use a single page repeatedly to display different contents. Therefore, to avoid duplicate meta descriptions on every page, create specific descriptions dynamically, explaining the contents of various pages.

← PreviousNext →