Monday, December 13, 2010

Adding META tags to ASP.net Pages

Adding META tags is a very beneficial way to improve your rankings in popular search engines like Google, Bing and Yahoo! For more information on the benefits of META tags, read Climbing Google's Search Results.

I will now explain how to add meta tags to your ASP.net (using C#) page. These tags are static and hard-coded for the most part. You will use this method on pages where the content doesn't change very often.

In your code-behind file (example: Default.aspx.cs), add the namespace "using System.Web.UI.HtmlControls;" This will allow you to use the HtmlMeta keywords.

Under the Page Load Event add:


// Render: <meta name="keywords" content="Some words listed here" />

HtmlMeta meta = new HtmlMeta();

meta.Name = "keywords";

meta.Content = "Some words listed here";

this.Header.Controls.Add(meta);

//Replace the "Some words listed here" string with the keywords you would for your specific page. Separate keywords with commas. It must be relevant to your page's content.


// Render: <meta name="description" content="Some words listed here" />

meta = new HtmlMeta();

meta.Name = "description";

meta.Content = "Some words listed here";

this.Header.Controls.Add(meta);

//Replace the "Some words listed here" string with a description of what your page's content. This will be displayed in search results. It must be relevant to your page's content.







// Render: <meta name="robots" content="index,follow" />

meta = new HtmlMeta();

meta.Name = "robots";

meta.Content = "index,follow";

this.Header.Controls.Add(meta);

//This will tell search engine spiders to index the current page

 

// Render: <meta name="date" content="2006-03-25" scheme="YYYY-MM-DD" />

meta = new HtmlMeta();

meta.Name = "date";

meta.Content = DateTime.Now.ToString("yyyy-MM-dd");

meta.Scheme = "YYYY-MM-DD";

this.Header.Controls.Add(meta);

//This will set the current page's date to the current date every time the page is loaded. This means that every time a search engine indexes the page, it sees the content as fresh content.


Do this for every page on your site to improve your search rankings!

Ayoba Designs: Web Design 

No comments:

Post a Comment