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

    There are no comments. Kick things off by filling out the form below.

» Leave a Comment