15 December 2007

ASP.net Making dynamic meta tags

I have been making a couple of new web sites lately, and one of my small hobbies is to make programming as easy and small as possible. I always prefer 1 simple line of code instead of 10 complex lines of messy code.

asp.net meta tags generator

So this time I have tried to make yet another thing easier, now you can implement dynamic meta tags to all of your asp.net pages with just one line of code, after you have imported my class file, you can either download it at the bottom of this page, or analyze and rewrite my asp.net code below.

The cool thing about this is that now you do not need to write all those meta tags in the header part of every single one of your pages.

Here is the thing. Just write the following line in the page load event of your asp.net page.

metatags.add("PUT IN YOUR PAGE TITLE HERE", "YOUR DESCRIPTION HERE", "KEYWORDS, GOES, HERE")

Now you can extract information from a database, xml or rss feeds and dynamically insert it into the line above in either the description, title or keywords field.

The code were are calling with the class file meta tags is here and can also be downloaded at the bottom and is easy to import to your asp.net project.

Public Shared Sub add(ByVal title As String, ByVal description_ As String, ByVal keywords_ As String)

Dim description As New HtmlMeta
Dim keywords As New HtmlMeta

page.Header.Controls.Add(keywords)
page.Header.Controls.Add(description)
page.title = title

keywords.Name = "keywords"
description.Name = "description"

description.Content = description_
keywords.Content = keywords_

End Sub

Download the asp.net class file to generate meta tags dynamic here.

No comments: