Implementing meta tags with master page in asp.net using c#

In this asp.net tutorial I will show you how to implement Meta tags with master pages in asp.net using C#.

The Master Pages introduced in ASP.NET 2.0 are a quite handy feature, however, master pages don't provide a good way to deal with the search engine optimization process of your website.

It is necessary for a webpage that it must have good Meta tags to be ranked well in search engines. This tutorial will show you how to extend @page directive on asp.net pages so that you can implement the meta tags of your need on each content page when you have master page.
I know bundle of methods to implement Meta tags with master pages in asp.net, let’s have a look over different methods.

Method 1

Use page.header control on Page Load event to implement the meta tags with master pages

protected void Page_Load(object sender, EventArgs e)
{

Page.Header.Controls.Add(new LiteralControl("<meta http-equiv='content-type' content='text/html; charset=UTF-8'/>"));

Page.Header.Controls.Add(new LiteralControl("<meta name='description' content=Description of the meta tag will come here.'/>"));

Page.Header.Controls.Add(new LiteralControl("<meta name='keywords' content='first keyword, second keyword, third keyword,etc'/>"));
}

Method 2
protected void Page_Load(object sender, EventArgs e)

{

//For description
HtmlMeta descTag = new HtmlMeta();

descTag.Name = "description";

descTag.Content = "My description for this page";

Header.Controls.Add(descTag);
//For Keywords


HtmlMeta keyTag = new HtmlMeta();

keyTag.Name = "keywords";

keyTag.Content = "first keyword, second keyword, third keyword,etc";

Header.Controls.Add(keyTag);

}

So these are the two methods I normally use to implement meta tags with master pages in ASP.NET using C#.

Enjoy SEO Process and Happy Coding


0 comments: