This project is read-only.

Using custom root/start pages with template parts

Topics: Developer Forum
Feb 24, 2009 at 6:33 PM
I am trying to implement template parts with a page i defined.

I started off by adding some installer hints to my page types...

[Definition(Name = "Custom Root Page", Installer = N2.Installation.InstallerHint.PreferredRootPage,SortOrder=1)]
public class MyRoot : LeftRight, IStructuralPage { }

That worked just fine.  That page inherted a class that pointed has its own template.

[Definition("Left Right")]
[AvailableZone("Corporate", "Right")]
[AvailableZone("Event", "Right")]
public class LeftRight : AbstractPage
    public override string TemplateUrl
            return "~/PageTemplates/LeftRight.aspx";

That page inherets the AbstractPage allowing for alot of the parts to be added.

I go to add a part.  I specifically tried the news list and i get an exception.  It seams that there is a reference to a class Find : N2.Persistence.GenericFind<ContentItem,StartPage>.  My root pages dont inheret the StartPage.  Any ideas as to how i can get around this?

Unable to cast object of type 'TopBottom' to type 'N2.Templates.Items.StartPage'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'TopBottom' to type 'N2.Templates.Items.StartPage'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Unable to cast object of type 'TopBottom' to type 'N2.Templates.Items.StartPage'.]
   N2.Persistence.GenericFind`2.get_StartPage() +56
   N2.Templates.Web.ThemeModifier.Modify(ContentPage`1 page) +20
   N2.Templates.Web.TemplatePageModifier.Modify(ContentPage`1 page) +126
   N2.Templates.Web.UI.TemplatePage`1.OnPreInit(EventArgs e) +97
   System.Web.UI.Page.PerformPreInit() +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282
Feb 24, 2009 at 7:50 PM
Looks like you're using a MyRoot object as the start page for a site based on the templates project. This project requires the start page to derive from N2.Templates.Items.StartPage since it's used to store information about the site such as theme and a few other details.

The installerhint is used to restrict which pages can be created for the root and start positions during installation (/edit/install)