Monday, February 16, 2009

Adding a Canonical Link Element in ASP.NET

Google, Microsoft and Yahoo announced support for a new "canonical" link element in the header of a page that will help clean-up duplicate url's that have been indexed from your site.

The canonical link for this page, for example, would be:

<link rel="canonical" href="">

To add this link tag to your header tag programatically using C# add the following to your Page_Load() function:

        protected void Page_Load(object sender, EventArgs e)
            HtmlLink link = new HtmlLink();
            link.Attributes.Add("rel", "canonical");
            link.Attributes.Add("href", "");



  1. Canonical url is very important. Now specially for google page rank.

  2. It rocks. Very good work.

  3. Web Design MacclesfieldApril 11, 2012 at 6:25 AM

    It is good to know that Canonical HTML Link tags (and other tags, i.e. Meta and CSS Links) can be added dynamically from the C# source code.

  4. my developer use this format in at the end of canonical, could you please tell me if this is correct"></link>