Adding a meta tag from the code behind ASP.NET C#

Below is the code that will allow you to add a meta tag from the code behind:

First ensure you have:

using System.Web.UI.HtmlControls;

Then use the below code

public static void AddMeta(HtmlHead head, string name, string content)
{
// Prepare the meta tag
HtmlMeta metaTag = new HtmlMeta();
metaTag.Name = name;
metaTag.Content = content;

// Add the meta tag to the head
head.Controls.Add(metaTag);
}

Then call the function like below:

AddMeta(Page.Header, "google-site-verification", "abcdefghijk");

Comments

Vinny @ 11/09/2011 17:39:12
Hey, you're the goto exerpt. Thanks for hanging out here.
vckomhsip @ 12/09/2011 13:53:03
Y0EBWS , [url=http://inwkslicgyrt.com/]inwkslicgyrt[/url], [link=http://ckshdokxxeyz.com/]ckshdokxxeyz[/link], http://ggmperdjenpx.com/
xjdxwqbjaa @ 15/09/2011 15:19:04
tJULKC , [url=http://vodfkmmkcpum.com/]vodfkmmkcpum[/url], [link=http://sikydsgrgtxk.com/]sikydsgrgtxk[/link], http://uynnnbzmzzmc.com/

Add a comment...

Name
Email Address
Comment