Dynamic SEO for c# website,How To Set Html Title, Meta Keywords & Meta Description From Asp.Net(C#.Net)

Task: Put SEO stuff (Title of page, Meta keyword, Meta description) in website using c# code in asp.net website/ web application. Onsite SEO –in Dynamic Website or E-Commerce Website.

Description: Now these day SEO is a very important thing in a Website (Dynamic Website or E-Commerce Website). When we work on SEO for website then we require the setup page title, Meta keyword, Meta description. So we require option for this in admin panel for Content Management System Website.

Here I use a small function for this, you can connect it to database and call on pageload.

C# Code for Dynamic SEO

  public void settitle(string pagetitle, string metakeyword, string metadescription)
    {
        HtmlTitle obj = new HtmlTitle();
        obj.Text = pagetitle;
        Header.Controls.Add(obj);

        //  or title can be set as
        Page.Title = pagetitle;

        HtmlMeta mt = new HtmlMeta();
        mt.Name = "keywords";
        mt.Content = metakeyword;
        Header.Controls.Add(mt);

        //  or can be set as, for position of meta tag
        Header.Controls.AddAt(2,mt);

        HtmlMeta mtd = new HtmlMeta();
        mtd.Name = "description";
        mtd.Content = metadescription;
        Header.Controls.Add(mtd);

       //  or can be set as, for position of meta tag
        Header.Controls.AddAt(2,mtd);
    }

2 comments:

  1. Thanks for this code. Helpful code.

    ReplyDelete
  2. Very Thanks for this code its very helpfull

    ReplyDelete