Monday, May 11, 2009

how to add mata keyword & meta description in ASP.NET?

There is no easy way to add but I have a simple method to introduce


pageEx.cs

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;

public class PageEx : System.Web.UI.Page
{

private HtmlMeta
metaDescription = new HtmlMeta();
private HtmlMeta metaKeywords = new
HtmlMeta();

public string Description
{
get { return
metaDescription.Content; }
set { metaDescription.Content = value; }
}


public string[] Keywords
{
get
{
if
(metaKeywords.Content == null)
{
return new string[] { "" };
}
else
{
return metaKeywords.Content.Split(new char[] { ',' });
}
}

set
{
if (value != null)
{
metaKeywords.Content =
string.Join(",", value);
}
}
}


public PageEx()
{
Init += new EventHandler(PageEx_Init);
}

void PageEx_Init(object
sender, EventArgs e)
{
//Add the description Meta control
metaDescription.Name = "description";
Page.Header.Controls.Add(metaDescription);
//Add the keywords Meta
control
metaKeywords.Name = "keywords";
Page.Header.Controls.Add(metaKeywords);
}


}



someasp.aspx


protected void Page_Load(object sender, EventArgs e)
{

this.Description = "the power 123";
this.Keywords = new string[] {
"Enquiries", "enquiry", "contact", "contacts", "email", "tel" };

}




Hope this helps :)

7 comments:

Sunmaster2020 said...

so good? how u get all those things?

u no be property agent? y be programmer?

Anonymous said...

Way cool! Some extremely valid points! I appreciate you writing this post and also the rest
of the website is really good.
Review my web page cheap nfl jerseys

Anonymous said...

My partner and I stumbled over here from a different website and thought I should check things out.
I like what I see so now i'm following you. Look forward to finding out about your web page for a second time.
Also visit my web blog http://www.nfljerseyswholesale49.com/

Anonymous said...

Hey! This is my first visit to your blog! We are a collection
of volunteers and starting a new initiative in a
community in the same niche. Your blog provided us beneficial information to work on.

You have done a outstanding job!
Also visit my web site - http://www.nfljerseysfreeshippings.com

Anonymous said...

Yes! Finally something about 2009 nfl jerseys best looking
nfl jerseys.
Feel free to surf my blog post ; Cheap nfl jerseys

Anonymous said...

Hello! Would you mind if I share your blog with my twitter group?

There's a lot of people that I think would really enjoy your content. Please let me know. Thank you
My web-site - cheapnikenfljerseysnews.com

mcshenee said...

y3s80z7c27 f9u36x1n89 p0e05n2z99 h7a81b6m01 s3n76f1g52 r5d13g4f65