C# ASP.NET SQL SERVER

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="http://guyellisrocks.com/coding/adding-a-canonical-link-element-in-asp-net/">

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", "http://guyellisrocks.com/coding/adding-a-canonical-link-element-in-asp-net/");
            this.Header.Controls.Add(link);
        }

 

» Similar Posts

  1. Combine, compress, and update your CSS file in ASP.NET MVC
  2. Automatically keeping CSS file current on any web page
  3. Search Engine Optimization

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=144

» Comments

  1. rudraksha avatar

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

    www.ommrudraksha.com

    rudraksha — May 12, 2011 7:39 AM
  2. rudraksha beads avatar

    It rocks. Very good work.

    rudraksha beads — September 20, 2011 2:41 AM
  3. Web Design Macclesfield avatar

    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.

    Web Design Macclesfield — April 11, 2012 6:25 AM

» Leave a Comment