Saturday, March 10, 2012

Add Title , Meta Descriptions and Meta Keywords Dynamically in Asp.net


Now We will discuss how we can use meta tags(Lean about Meta elements) in our aspx pages dynamically, Meta tags are the important for any webpage for better rankings in search engine and its is important for SEO. Meta tags can be added dynamically inasp.net application if you have a application where pages generated from the data which is in your SQL in that case using same meta tags in aspx page is not good for seo like if your page is generated dynamically with database then you should use dynamic meta tags in your pages. like you have a page name profile.aspx?userid=1 and this is a user profile page and this is a public page(anyone can see this without login like in Facebook) in that case you can't set same title and description in your pages, you have to add dynamic tags in page load of the profile.aspx page check example below. 

we have a table in database pageDetails which have details of each user profile page like title description and keywords you can see on page load event of the profile page we select data from this table where user id is one then we execute query with the help of our datacontext layer then we fill the title ,metadescription and metakeywords tags of that user.


if (!IsPostBack)
        {
string query = "select * from pageDetails where userid ='1'" ;    
              DataTable dt = new DataTable();

             dt = dc.get_datatable(query);
            Title = dt.Rows[0]["title"].ToString();
            MetaDescription = dt.Rows[0]["description"].ToString();
            MetaKeywords = dt.Rows[0]["Keywords"].ToString();
        }

You can also use this.MetaDescription  or this.MetaKeywords  in your code.


No comments:

Post a Comment