Adding Meta Tags via Code - C# in ASP.NET

So here is a question why would you want to add your Meta Tags via code? Kinda silly right? Cause if you were a great developer you probably have a whole list of meta tags you have created for your portfolio of web sites right?

Well if you are the developer who has those templates you most likely will stop reading here and think this mikedopp character is kinda wierd or is one of those "because you can" type people. I know I am adding much too much fluff to this whole entry and spending too much time with words so here is the code to add meta tags to your on load event of either your master pages or just to that web site that you need to get out the door tonight.

private void AddMetaTags()
    {
        if (this.Page != null)
        {
            base.Title = Server.HtmlEncode(this.Page.Title);
            base.AddMetaTag("keywords", Server.HtmlEncode(this.Page.Keywords));
            base.AddMetaTag("description", Server.HtmlEncode(this.Page.Description));
        }
    }

As an added bonus you could just create a large list of meta tags in your web.config file or another dot config file within your application or site that is just read into the site on_load.

There is also the possibility of having a large SQL/XML table that holds all your tags and is read in based upon the name of the page and content that is requested.

#Region ---This is where I go on a rant--- Feel free to get some popcorn and a diet mountain dew---

However since the only search provider that reads meta tags is MSN Live search and not google as I have been told (I still don't believe that).

There is no point to this post. So go ahead an move on to the next post on how to put all your keywords in a database and read them into the page content based on the same factors (for Google of course).

#EndRegion---End of rant

 

No Comments