Friday, 21 February 2014

Add Page Meta tags dynamically in asp.net using C#.

Meta tags are very much important for you web page, search engine use Meta tags to index you site. So some time we need to change meta tags dynamically in case of dynamic pages in asp.net

protected void Page_Load(object sender, EventArgs e)
{
HtmlHead headTag = (HtmlHead)this.Header;
// Set the page title
headTag.Title = "Title of Page";
// Add a Description meta tag
HtmlMeta PagemetaTag = new HtmlMeta();
PagemetaTag.Name = "Description";
PagemetaTag.Content = "Customized Description tag of the page";
headTag.Controls.Add(PagemetaTag);
// Add a Keywords meta tag
PagemetaTag = new HtmlMeta();
PagemetaTag.Name = "Keywords";
PagemetaTag.Content = "Customized Keyword tag of the page";
headTag.Controls.Add(PagemetaTag);
}