I am using ASP.NET with MasterPages. Thus i cant just place this link in my pages that reference my MasterPage.
<link rel="canonical" href="http://www.erate.co.za/" />
I need to place this link in though my Page Load of each one of my pages. How would i do this through code? I am using VB.NET but C# will also help me in the right direction.
This is how i did it for my DESCRIPTION tag in my code behind.
Dim tag As HtmlMeta = New HtmlMeta()
tag.Name = "description"
tag.Content = "Find or rate any company in South Africa for FREE and rate them"
Header.Controls.Add(tag)
Thanks in advance!
This is what i had to do..................
Dim seoTag As HtmlLink = New HtmlLink()
seoTag.Attributes.Add("rel", "canonical")
seoTag.Href = "http://www.erate.co.za/"
Header.Controls.Add(seoTag)
More information Here
Why not create your canonical element as a server control:
<link rel="canonical" href="" runat="server" id="canonical"/>
Then manipulate the canonical object in your page (or master page) class. Generic tags are treated as instances of HtmlGenericControl
which allows one to set arbitrary attributes:
canonical.Attributes["href"] = whatever;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With