Scribble Designs: Web Design Northern Ireland

SEO – Automating Meta Description For Dynamic ASP.NET Pages

By gerardmcgarry on 18th April 2007, filed in General, Programming, Search Engine Optimisation. You can skip to the end and leave a response. Pinging is currently not allowed. Tags: , ,

If you have dynamic content in an ASP.NET web application, it’s relatively easy to create Meta description tags from the content stored in your database.

I got the idea to do this after installing the Head META Description plugin for WordPress and realising that I wasn’t automatically doing this in my ASP.NET applications.

Why META Description Is Important

Although Search Engines don’t place as much weight on META tags these days, the Description tag in particular is useful, because it helps to control what a search engine displays in its results.

If you don’t specify text to use, the search engine will create the description line itself. It may come out as unreadable garbage. However, if you do specify a description tag, you’ll get a coherent sentence that can act as teaser content in the search engines.

How To Generate META Description In ASP.NET

OK, let’s roll up our sleeves and get started. The first assumption I’m making is that you’re storing your content in a database of some description and that you have a large text field that stores the content of each page.

Processing The String

Below I’ve shown the function which we’ll use. Firstly it strips any HTML from the string using another function, then we split the string into an array which allows us to easily select the first 20 words with the For i = 0 To intLimit loop.

If the string ends with an incomplete sentence, we add an elipsis “…” to the end of the string to signify that there’s more to read. Finally, we return the formatted Description text.

Public Shared Function extractMeta(ByVal docToParse As String) As String
	docToParse = vbStripTags(docToParse)
	Dim oArray As Array = Split(docToParse, " ")
	Dim strOutput As String = ""
	Dim intLimit As Integer = 20, i As Integer
	For i = 0 To intLimit
		strOutput &= oArray(i) & " "
	If UBound(oArray) - 1 > intLimit Then
		strOutput &= "..."
	End If
	Return strOutput
End Function

Using HTMLMETA to Insert META Description

I set the META Description at the point where I’m building the page from the database. In a nutshell though, the following code will add the Description to your page (I’m using a SqlDataReader object to read the various database fields):

Dim metaDescription As New HtmlMeta
metaDescription.Name = "description"
metaDescription.Content = extractMeta(oReader("news_text"))

You’ll probably need to do a little bit of jiggery-pokery with this to get it right, but in general it works well.

Optimising Your Descriptions

When you’re writing for the web, you need to create compelling content for your readers. Now that your descriptions are optimised, you should try to make the lead sentence of each article more compelling.

The two areas to focus on are using relevant keywords within those first 20 or so words, and writing a sentence that will make people want to read more.

Basically, you’re catering to the search engines with the keywords and your human audience with an interesting introduction. The keywords will hopefully improve your ranking, while a leading sentence will hopefully attract more searchers to click through to your site.

That’s the goal anyway! Good luck with your new META tags!

Leave a Reply