Skip to content


Dynamically add tags to ASP.NET page

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

I was creating a web-application for one of my clientele, where I was supposed to add Meta-Tags dynamically to ASP.NET page. This kind of worried me for some time. Then I thought, let me open up the Visual Studio 2005 IDE.

I was playing around in Object Browser with System.Web namespace when I found a new class…

HtmlMeta…! Hurray!

Let me try, was my first thought and the results were beautiful.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
///
Summary description for CommonFunctions
/// </summary>

public static class CommonFunctions
{

public static void SetHeading(Page pg, string sHeading)
{
HtmlMeta meta = new HtmlMeta();
meta.Name =
“keywords”;
meta.Content =
“Company Name, products,” + “,” + sHeading ;
pg.Controls.Add(meta);
}
}

The site is now Search-Engine Optimized. The content can be changed dynamically!


Related Posts:

Posted in ASP.NET, C#, Microsoft .NET.

Tagged with .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.