I am hoping that you can point me in the right direction to resolve an issue I am facing.
I have written code to insert a canonical url into the pages source. The URL is pulled from whatever has been in the Canonical property on the page.
Here is the code:
<link rel="canonical" id="canonical1" <%=EPiServer.Web.UrlRewriteProvider.UrlPreventRewriteAttribute %>="true" href="<%= Canonical %>" />
I have created the propery in the pagetype of the homepage using Admin Mode > Page Types > Add Property.
However, when I attempt to load the page I see CS0103: The name 'Canonical' does not exist in the current context.
Am I incorrect in thinking that the property is being correctly created using this method? If so, how should I be creating it for this to work correctly?
Thanks in advance for your help!
The property will be created but there won't be any code accessor for it. You need to fetch it using for instance CurrentPage["Canonical"]. Alternatively use Page Type Builder which allows you to define page types and properties in code.
The fetch solution worked perfectly! I will start reading up on page type builder, as I expect this will be very useful in future.