views:

394

answers:

2

Hi,

Can someone please help me trying to figure out how to simply write the meta tags in an asp.net page. The meta tags have been inserted in the page and I just want to loop through them and write the keywords tag. I don't have a probably adding dynamically, just reading.

Thanks in advance.

+2  A: 

.

using System.Web.UI.HtmlControls;
// ...
List<HtmlMeta> metas = new List<HtmlMeta>();
foreach (Control c in this.Page.Header.Controls)
    if (c.GetType() == typeof(HtmlMeta))
    {
        HtmlMeta meta = (HtmlMeta)c;
        if (meta.Name == "Keywords")
            meta.Content = "content goes here";
        break;
    }

Edited to make useful to your situation...

tsilb
This doesn't seem to work with custom meta data
James Campbell
It works with any META tag. Just alter the .Name and .Content and it will produce whatever META you need. Failing that, you can always use a LiteralControl and parse the markup manually.
tsilb
A: 

Below link shows you how to manage your Meta tags & even SEO options.

http://www.programminghelp.com/web-development/asp-net/using-sitemap-and-masterpages-to-set-meta-tags-in-asp-net-and-c/

Ravia