meta tag keywords

Topics: ASP.NET 2.0
Mar 16, 2012 at 5:42 PM
Hi,

i want to add new tags in meta name="keywords" content... how can i do??

i know that meta name keywords include only categories and not pages... can i add new tags in meta name keyworkd??

can you help me?

thank you

Fabry
Coordinator
Mar 16, 2012 at 9:02 PM

Take a look at the code at default.aspx.cs. You can modify it to add your own keywords or handle it differently.

private void AddMetaKeywords()
{
	if (Category.Categories.Count > 0)
	{
		string[] categories = new string[Category.Categories.Count];
		for (int i = 0; i < Category.Categories.Count; i++)
		{
			categories[i] = Category.Categories[i].Title;
		}

		string metakeywords = Server.HtmlEncode(string.Join(",", categories));
		System.Web.UI.HtmlControls.HtmlMeta tag = null;
		foreach (Control c in Page.Header.Controls)
		{
			if (c is System.Web.UI.HtmlControls.HtmlMeta && (c as System.Web.UI.HtmlControls.HtmlMeta).Name.ToLower() == "keywords")
			{
				tag = c as System.Web.UI.HtmlControls.HtmlMeta;
				tag.Content += ", " + metakeywords;
				break;
			}
		}
		if (tag == null)
		{
			base.AddMetaTag("keywords", metakeywords);
		} 
	}
}

Mar 16, 2012 at 10:11 PM

i know this function but if i want to add also Pages???

how can i do?

Thanks

Fabry