Adding Meta tags dynamically

Posted by Raj.Trivedi under ASP.NET category on | Points: 40 | Views : 1659
Go to MS Visual Studio. Create a New Website.
Add a Web Page.
Now go to the code behind of that page.
Import the following name space
using System.Web.UI.HtmlControls;
First we will give the title to the page.
All the code will go into the page load event.
Over we will see how we can use descriptive text for meta tags and how to assign keywords and how to assign author for the meta tag.

// Code Behind
Page.Title = "Info about Meta Tags"; // This will set title to the page.
HtmlMeta tag = new HtmlMeta(); // creating the instance of HTML Meta.
tag.Name = "MyWebsite" // assigning the name of the tag
tag.Content = "tag.Content = "Providing IT Solutions in India and Mumbai,Cheap CMS Solutions for India"; // here we are assigning the content to meta tag.These are not keywords.You can either specify keywords or description in this i have used description.
Header.Controls.Add(tag); // adding the tag to the page.
// Now we will see use of keywords.
HtmlMeta keywords = new HtmlMeta(); //creating the instance of HTML Meta.
keywords.Name = "keywords"; // here we are defining the variable for keywords to store keywords
keywords.Content = "IT Solutions,E-Commerce Solutions"; // these are keywords that will crawl from search engines to search your page
// Now we will define the author of meta tags
HtmlMeta author = new HtmlMeta(); //creating the instance of HTML Meta.
author.Name = "Author"; // assigning the name of the tag
author.Content = "Raj.Trivedi"; // this the name of the author.
Header.Controls.Add(author); creating the instance of HTML Meta.

In the above code you can either use both methods for completing the meta tags work.

Hope you would like this article.
Sharing is Caring.

Comments or Responses

Login to post response