Copied to clipboard

Flag this post as spam?

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


  • Funka! 398 posts 661 karma points
    Jun 24, 2013 @ 20:48
    Funka!
    0

    How to render a page programmatically from outside the umbraco request pipeline?

    Hello there! The new Content API and MVC support in version 6+ of umbraco seems promising but I'm unsure if what I want to do is possible:

    In an external MVC4 application that I am running alongside of Umbraco (e.g., one that is reached via custom routing and is ignored by the umbracoReservedPaths setting), how can i programmtically render a particular page using its current template?

    It seems whatever I do, I need to have something called a PublishedContentRequest which is not created in the scenario I described nor is even possible to do it seems (constructor is internal).

    I have found out how to obtain my desired page as an IPublishedContent object using new UmbracoHelper(UmbracoContext.Current).TypedContent(1234)  but apparantly all of the magic bits I would need in order to render this are not available unless umbraco is "in charge" of my routing.

    Is there any way to do what I'm asking?

    Thank you!

  • Funka! 398 posts 661 karma points
    Jul 02, 2013 @ 00:51
    Funka!
    0

    I'm resigning myself to say this simply isn't possible. I was about to create a feature request over at the issue tracker, but I think I must be the only person in the world who wants to do this right now, so I'm not going to clutter things up over there.

    For anyone running across this at some later time with this same need, what I've come up with now is an external HttpWebRequest call into the umbraco site from my MVC app (yes, they are both hosted on same domain and server), then using Html Agility Pack to parse the retrieved HTML, caching this for a short while, then using a custom view engine to shove my own app into the shell of what I've scraped. (This last part still in progress.)  It doesn't seem possible to use any of the functionality provided by Umbraco unless it is handling the request itself, which was not what I wanted in my case. But at least this way the client can have consistent navigation bars, sidebars, footers etc. and still think of their site as a single thing.

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Jul 04, 2013 @ 22:05
    Damiaan
    0

    Hi, I tried it and failed also.
    The only way to integrate 'something'.  Was to use custom routes.  But as you have found out already, this limits you in calling Umbraco specific stuff from your Views.

    Kind regards

  • Anand 2 posts 22 karma points
    Nov 12, 2013 @ 13:25
    Anand
    0

    Hi Funka!

    Elsewhere you had mentioned about trying to create a Umbraco site with Views/Models retrieving data from a custom database (or rather a non-Umbraco database). Were you successfult with this? I have a situation where I have to create a Umbraco site that pulls a list of "Jobs" from a non-Umbraco database (Currently this is a database but may be a REST service in the future). Try as I might, I am not able to get this working. I have even referred to your other post (http://our.umbraco.org/forum/developers/api-questions/41560-How-do-I-integrate-an-MVC-form-into-the-Umbraco-CMS) but have got nowhere. The page loads fine but the Partial View is not hitting the Controller and hence returns a "NULL Model" ! Do you have anything to share that may help? I asked the same question in Stackoverflow (http://stackoverflow.com/questions/19912505/integrate-existing-mvc-view-into-umbraco) but the answer seems to be to use Webpages and User controls (like the older versions) but I don't like that 

    Any ideas would help !!

    Cheers
    Anand 

     

  • Funka! 398 posts 661 karma points
    Nov 13, 2013 @ 20:48
    Funka!
    0

    Hello Anand,

    No, I was never able to do what I wanted with Umbraco while using custom routing. (Recall that custom routing executes before Umbraco ever gets involved in the pipeline, thus why Umbraco isn't available to render any templates.) After months of struggle I lost interest and ended up using some horrible mess to get the job done and haven't looked back at it since.

    However... if you are not using "custom routing", then you don't need to worry. I didn't immediately get the impression from your post that you would need to use "custom routing", but instead might be able to just use "route hijacking". You could code whatever database logic you want in a custom controller, and use Umbraco engine perfectly fine to show your results in an Umbraco view. (So, you would be "inside" the umbraco request pipeline, not "outside" of it as I had found myself.)

    I'd recommend taking a look at the Custom Controllers documentation page a.k.a. hijacking routes. It's all very confusing at first glance but important to remember not to confuse custom routing (i.e., my problem) with a custom controller and route hijacking (i.e., what you probably want to use).

    Good luck to you!

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Nov 29, 2013 @ 09:34
    Damiaan
    0

    Hi Anand,

    You might want to follow this post: http://our.umbraco.org/forum/developers/extending-umbraco/41367-Umbraco-6-MVC-Custom-MVC-Route?p=4

    Shannon just came up with a solution.

    Kind regards
    Damiaan

Please Sign in or register to post replies

Write your reply to:

Draft