Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Kaplan 86 posts 139 karma points
    Dec 21, 2011 @ 21:42
    Paul Kaplan
    0

    Migrating pages that inherit from a class that in turn inherits from System.Web.UI.Page


    I'm trying to migrate an existing .NET site/app to Umbraco.  So far, I've migrated our master pages to Umbraco templates.

    Now I'm trying to migrate the actual .aspx pages.  Many of these .aspx pages inherit from a custom base class page which in turn inherits from System.Web.UI.Page.

    So, when I try to preview a page in Umbraco, the master has a user control that calls a method in the custom base class.  Meanwhile, the page that is passed to the method does not inherit from our custom base class, rather it's an Umbraco page, and I get the error message: Unable to cast object of type 'ASP.default_aspx' to type 'Com.MyCompany.MobileComponent.MobileComponentPage'.

    Any ideas how to make this work whilst minimizing the changes to that base class?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 21, 2011 @ 22:01
    Jan Skovgaard
    0

    Hi Paul

    When you create document types in Umbraco and assign them to document types in Umbraco you can create content in the content section. These pages are turned into .aspx pages when you try to visit them in the browser...so you really should not migrate the .aspx pages from your old application manually like this.

    If you for some reason need to have some custom .aspx pages on your website you should create a folder to keep them in and then add the path to the folder to the umbracoReservedPaths key in the web.config file.

    Hope this helps - If I'm missing your point then please explain your approach for converting your existing site :)

    /Jan

  • Paul Kaplan 86 posts 139 karma points
    Dec 21, 2011 @ 22:43
    Paul Kaplan
    0

    Hi Jan,

    Sorry, I probably didn't explain it very well.  I've created document types and templates, and have not even attempted to migrate actual aspx pages yet.  I understand that migrating manually (i.e. copying the .aspx files) is not a good idea, and I don't want to subvert the Umbraco system.  I'm willing to do the work of creating new pages within the Umbraco back office.

    I did copy/paste the master code from the site into a new Template that I created, using the back office, and with slight modifications they seem OK.  I also copied the library dlls from the site into the umbraco bin folder.

    My first attempt was to create a new Document Type which uses the templates I mentioned, and then create a new empty page in the content section.

    The problem is that the master page calls one of our user controls with a reference to the current page, and when the user control receives that reference, it assumes the page is a 'Com.MyCompany.MobileComponent.MobileComponentPage' rather than a 'ASP.default_aspx' and thus throws the cast exception.

    It struck me that one way to solve it would be to override Umbraco's default.aspx.cs, but that does not seem appealing, particularly when Umbraco provides updates.

    -- Paul

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 21, 2011 @ 22:50
    Jan Skovgaard
    0

    Hi Paul

    I'm not that skilled in C# and ASP.NET stuff but I guess you should not include the custom stuff in the master pages but rather create som macroes based on usercontrols where you can have your logic instead and then place the macroes in the masterpages templates.

    You can see an introduction video about it here: http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls.aspx and you can read some more information about creating your first umbraco macro based on a user control here: http://skiltzonnet.blogspot.com/2008/01/creating-you-first-umbraco-user-control.html

    I hope this helps.

    /Jan

  • Paul Kaplan 86 posts 139 karma points
    Dec 23, 2011 @ 00:49
    Paul Kaplan
    0

    I got sidetracked on a few other projects, isn't it always the way it goes?   But I wanted to report that I might have a solution.  I'm working on it now.

    To recap, the problem is that every page, as far as I can tell, is wrapped in the Umbraco default page, and thus our methods throw a cast exception because they are expecting an object that is one of our pages, not the Umbraco default page.

    I'm trying this - I moved all the code from our page class into a master page class.  This class is inherited by an Umbraco template, which is really just a master page.  Then in the method that gets the default page, it can get the master via:

    MobileComponentMasterPage masterPage = (MobileComponentMasterPage)Page.Master;

    I think this is going to work, I have a bunch more things to get sorted though.  I will report back if and when I get one of our pages working with Umbraco.

    Regards,

    Paul

     

     

  • Paul Kaplan 86 posts 139 karma points
    Dec 30, 2011 @ 01:47
    Paul Kaplan
    0

    Here's the follow-up.  The strategy above actually works!!  And I've been able to import our existing user controls by wrapping them in macros, which I then inserted into the templates, etc.

    Originally I had looked at the *other* CMS, but I really think Umbraco is much more suitable for this application, because 1) migrating an existing site seems much more straightforward and 2) in general, Umbraco seems to impose less and is more flexible.

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft