AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Wednesday, 15 June 2016

How to dynamically add title, meta tag keywords & meta tag description on the web page?

In this blog post I am going to discuss how to dynamically add Title, meta tag keywords & meta tag description on the ASP.NET website. Please follow below steps to add meta tags.

Step 1- Add content place holder in your Head Section of Master Page.
<head id="Head1" runat="server">
    <asp:ContentPlaceHolder ID="HeadMetaContent" runat="server">
    </asp:ContentPlaceHolder>
</head>

Step 2- Add following method in your aspx.cs page to add meta content. 
    protected void Page_Load(object sender, EventArgs e)
    {
     DOSEO();
    } 
    #region--Do SEO--
    public void DOSEO()
    {
        ContentPlaceHolder CntHead = (ContentPlaceHolder)this.Master.FindControl("HeadMetaContent");
        if (CntHead != null)
        {
            //Add Page Title
            this.Page.Title = "Add your Title here";

            //Add Keywords Meta Tag
            HtmlMeta keywords = new HtmlMeta();
            keywords.HttpEquiv = "keywords";
            keywords.Name = "keywords";
            keywords.Content = "Add your keywords here.";
            CntHead.Controls.Add(keywords);

            //Add Description Meta Tag
            HtmlMeta description = new HtmlMeta();
            description.HttpEquiv = "description";
            description.Name = "description";
            description.Content = "Add your description here";
            CntHead.Controls.Add(description);
        }
    }
   #endregion
You can also maintain Title, keywords & description for each page in database & append it on each page.

0 comments :

Post a Comment

  • Popular Posts
  • Comments