Set meta tag in programmaticaly for creating seo friendly websites

Category > CSHARP || Published on : Tuesday, July 29, 2014 || Views: 17374 || ASP.NET Meta tags SEO ASP.NET Meta Keywords Meta Description SEO friendly websites


Search Engine Optimization or SEO helps a website to get generic traffic from internet and traffic is very important for a website to retain in the market and when we are developing Search Engine Optimization or SEO friendly ASP.NET Websites, the first and important basic thing for Search Engine Optimization or SEO is the META Tags(like Keywords, Title, Description), while generally all Serach Engine like, etc are looking for these META Tags(like Keywords, Title, Description) while making querying the Databases.


In last articles, We have learned How to validate or check whether checkbox is checked or not using ASP.NET and jQuery with example. and How can we call a C# Method from ASPX Page or Code Behind page and now we will learn how to Set meta tag in ASP.NET programmaticaly for creating SEO friendly websites.

Here we will set the SEO MetaTags "Keywords" and "Description" from the CodeBehind of the ASPX page. Here we are using ASP.NET as main core technology

So lets start the example:

Step 1: Create a ASP.Net Empty website by starting Visual Studio 2013 or any other Visual Studio Edition. You can download the free edition from here and also get other details regarding Visual Studio Alternate Text
Alternate Text Step 2: Create a new Web form page, by right clicking on solution explorer > Add new Items > Web Form and name it as you like, mine is "SetMetaTags.aspx" Alternate Text
Alternate Text Step 3: In the Code Behing of the web form you just added, write the following codes. In the we are creating a two instances of HTMLMETA class and setting their name and content property and finally add that to the Page header Control

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class SetMetaTags : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        HtmlMeta mKey = new HtmlMeta();
        mKey.Name = "";
        mKey.Content = "SourceCodehub, free programming articles, Codes ";
        HtmlMeta mdesc = new HtmlMeta();
        mdesc.Name = "description";
        mdesc.Content ="Here you will get free source codes";

Output will be like this....

Alternate Text

So In this article we learn how we can Set meta tag in ASP.NET programmaticaly for creating seo friendly websites.

Download Source Codes