About this article

Written by:
Posted:
30/07/2010 15:49:15

About the author

Imar Spaanjaars is the owner of De Vier Koeden, a company specializing in consultancy and development on the Microsoft .NET platform and DynamicWeb.

Interested in custom development or consultancy on DynamicWeb or .NET? Then contact De Vier Koeden through the Contact page.

If you want to find out more about Imar Spaanjaars, check out his About page on this web site or check out his personal website.

Quick Tips - Custom Modules - Changing the Meta Description of a Page

NOTE: the concepts presented in this article are now considered obsolete possibly because better alternatives are available.

In an earlier article I showed you how to change the title of the page from within a custom module. From a Search Engine Optimization perspective, you may also want to update the meta tag for the description of the document. Search engines use this to index your document, and quite often the contents of this meta tag are displayed as the description of the page in the search results on many search engines. Setting the meta description of the page is just as easy as the setting the title, although you may not discover how to do it in IntelliSense directly.

To set the meta description of the page in a custom module, you access the Pageview property of the ContentModule class, the base class for all your custom modules. The Pageview property has a Meta property which has a MetaTags collection property. By indexing this collection using "Description" as the key, you can change the meta description of the page:

[AddInName("YourModuleName")]
public class Frontend : ContentModule
{
  public override string GetContent()
  {
    // Other code here to create HTML
    Pageview.Meta.MetaTags["Description"] = "Your custom description here";
    
    // Other code here to return the HTML
  }
}

When rendered in the browser, your description ends up as a <meta /> element in the <head /> of the page. Here's an example of the <meta /> tag from the page you're currently reading:

<meta name="Description" content="This quick tip shows you how to change 
                    the meta description of a page from a custom module." />  
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing