Mar
24
2013

SEO add meta tags dynamically in ASP.NET C#

Here is an example how to add meta tags such as page title, meta description, and meta keywords in asp.net C#.

 

namespace reference use: using System.Web.UI.HtmlControls;


Add the following code into your (.aspx.cs) page:

protected void Page_Load(object sender, EventArgs e)
        {
            // set page title
            Page.Title = "Welcome to Phi's Homepage - PhiBui.com";

            //Page description
            HtmlMeta pagedesc = new HtmlMeta();
            pagedesc.Name = "Description";
            pagedesc.Content ="Phi Bui is Software Engineer & IT Professional in Louisville KY";
            Header.Controls.Add(pagedesc);

            //page keywords
            HtmlMeta pagekeywords = new HtmlMeta();
            pagekeywords.Name = "keywords";
            pagekeywords.Content = "Programmer,ASP.NET,SEO,C#,C/C++,HTML/CSS,JavaScript/JQuery,MS SQL Database,MySQL Database,PostgreSQL";
            Header.Controls.Add(pagekeywords);
        }

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Calendar

<<  April 2020  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar