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..................
More information Here
Try to use: First create BasePage class like this:
Seconds create your .aspx pages that inherit from the base class like this:
Last step:
Remember to add in C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\schemas\html\page_directives.xsd the attribute:
in the complexType section
As per Richard's answer, in your page code side you will need to reference the master page. Try:
or the VB equivalent :)
I have the following set up.
Create a class that inherits from System.Web.UI.Page as a "BasePage" type class.
Add a method to that:
Then you can create your .aspx pages that inherit from the base class, and then call AddHeaderLink on that:
Why not create your canonical element as a server control:
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: