Copied to clipboard

Flag this post as spam?

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


  • Bryan Drenner 37 posts 59 karma points
    Feb 03, 2012 @ 21:38
    Bryan Drenner
    0

    How do you call a custom method on a page, particularly before its content is rendered?

    This seems like a really basic question.  I couldn't find a forum that was definitively appropriate, but this forum seems to be the most promising.  I would appreciate guidance on my specific issue, as well as advice on forums that would be more appropriate for this kind of question.

    My problem is: I need to execute a custom library's methods on certain pages and to allow those pages to supply unique parameters.  One of these methods maintains a session with a proprietary web service, and it would potentially need to trigger redirects based on the status of that web service.  This method would ideally execute as soon as Session is available, and preferably before any further logic or content rendering.

    With Umbraco 4 and ASP.NET Web Forms, my solution was to run my custom methods via Page_Load() on user controls, which I imported into Umbraco as macros and then placed into particular templates.  For the user controls with methods that needed to run as preliminary to the rest of a page, I placed them at the top of the template to ensure that they ran first.

    Using Umbraco 5 and the MVC Framework, my thought is to create custom controllers with child actions, and then render them in the templates.  For the page-preliminary methods, I would "render" their child actions at the top of each template, much like I did with user controls.  This feels ugly to me.

    My questions are:

    • Are child actions the best way to execute custom code on certain Umbraco pages?
    • What alternatives should I consider?
    • Are there any basic guidelines and best-practices for developing child actions for use in Umbraco, particularly as macros?
    Thanks,
    Bryan

Please Sign in or register to post replies

Write your reply to:

Draft