Google
Web Netomatix

How to programatically set meta tags on ASP.Net page

by Admin 5. November 2009 06:34

When we are creating a web site, one of the main goal we all have is that out site should be listed on first page of search engines like Google, Bing, Yahoo, Baidu etc. As we all know that in SEO world, one of the first thing we all look for in the page is meta tags in header of the page. In the past there was no direct way to set the meta tags on a page programatically when developing ASP.Net web site. We all used the work around of adding metaelements in header element of the page. You can read my previous post Adding meta tags to asp.net page dynamically about that technique. With ASP.Net 4.0 microsoft has introduced following two properties on that allow you to set the meta tags on a page.

  • MetaDescription
  • MetaKeywords

Following code snippet shows how it is used in your code.


public partial class _Default : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
  SetMetaTags();
 }
 private void SetMetaTags()
 {
  Title = "Hello Meta";
  MetaDescription = "This is description of my ASP.Net 4.0 page.";
  MetaKeywords = "ASP.Net,.Net4.0,Meta";
 }
}

And it works. You can see from the source of the page as shown below.

<head>
<title>Hello Meta</title>
<meta name="description" content="This is description of my ASP.Net 4.0 page." />
<meta name="keywords" content="ASP.Net,.Net4.0,Meta" />
</head>

Views: 1177

Tags:

.Net | ASP.Net

Comments

11/25/2009 6:28:51 AM #

cash loans

thanks!  very helpful post!! like the template btw ;)

cash loans United States

12/21/2009 7:45:57 AM #

New York Payday Loans

Interesting ... as always - is your blog making any cash advance ? ;)

New York Payday Loans United States

12/27/2009 9:39:23 PM #

Cheap Car Hires Adelaide

You have apprised about a very important fact in web designing.  I think this script will prove very profitable for webmaster to boost up the ranking of their sites.

Cheap Car Hires Adelaide United States

1/11/2010 12:50:44 AM #

Alcohawk

This is a really nice article. I am sure a lot of people will benefit from it. Thanks!

Alcohawk United States

2/4/2010 5:08:11 AM #

ucvhost

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

ucvhost United States

2/6/2010 1:14:18 AM #

dfg

hi..

dfg United States

2/6/2010 1:25:35 AM #

How to Clean an Aboveground Swimming Pool

I’m having fun exploring ASP.Net, I just want to ask if you have some codes that would help me to speed up my internet connection? I’m very desperate to know it. Thanks a lot!

How to Clean an Aboveground Swimming Pool United States

2/6/2010 7:16:52 AM #

ucvhost

resource mention very very useful for me ..keep up continue.

ucvhost United States

2/12/2010 3:05:06 AM #

ucvhost

i. I wanted to drop you a quick note to express my thanks. I've been following your blog for a month or so and have picked up a ton of good information as well as enjoyed the way you've structured your site.

ucvhost United States

Add Comment


(Will show your Gravatar icon)

  Country flag


  • Comment
  • Live Preview
Loading