London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

CS0103: The name '' does not exist in the current context

Vote:
 

Hi all,

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!

James

 

#60114
Jul 18, 2012 12:40
Vote:
 

Hi James,

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.

#60121
Jul 18, 2012 14:14
Vote:
 

Thanks Joel,

The fetch solution worked perfectly! I will start reading up on page type builder, as I expect this will be very useful in future.

#60127
Jul 19, 2012 9:24
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.