Yet Another Blog on ASP.NET and Some Other Stuff

Update Title and Meta Tags Dynamically in ASP.NET

Posted in ASP.NET, C#, SEO, Web Development by Mustafa Basgun on April 30th, 2008

If you are using master pages, updating your title or meta tags (such as “description” and “keywords”) may become an important subject because of the SEO purposes. Since there are several ways to accomplish this, here is my way in C# to do so.

One Response to 'Update Title and Meta Tags Dynamically in ASP.NET'

Subscribe to comments with RSS or TrackBack to 'Update Title and Meta Tags Dynamically in ASP.NET'.

  1. Ryan Bell said, on June 12th, 2008 at 1:16 pm

    Instead of looping through to remove all meta tags and re-adding them, you can just set the ID of the tag when you create it and use the FindControl method with your specified ID to locate the specific meta tag that you want to modify.

    //Creation code
    metaKeywords = new HtmlMeta();
    metaKeywords.Name = “keywords”;
    metaKeywords.Content = strKeywords;
    metaKeywords.ID = “cntrlMetaKeywords”;
    this.Page.Header.Controls.Add(metaKeywords);

    //Find code
    metaKeywords = (HtmlMeta)Page.Header.FindControl(”cntrlMetaKeywords”);
    metaKeywords.Content = strNEWKeywords;

    Ryan
    http://www.newsorviews.com

Leave a Reply