Copied to clipboard

Flag this post as spam?

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


  • Braydie 148 posts 346 karma points
    Nov 16, 2012 @ 12:20
    Braydie
    0

    Setting the Masterpage via code in 4.10

    Hi,

    Prior to 4.10 I had an event handler that dynamically swapped the masterpage of a page. This event was fired on UmbracoDefault.BeforeRequestInit and the sender object was converted to a System.Web.UI.Page, where the MasterPage property would be changed.

    Now in 4.10 the same property is null. I understand that the request pipeline was rewritten for 4.10 and that this is not how the masterpage is set now, so I was wondering if anyone knows at what point Umbraco sets the masterpage for a node so that I can jump in and swap it.

    Thanks!

  • Stephen 767 posts 2273 karma points c-trib
    Nov 16, 2012 @ 19:20
    Stephen
    0

    The BeforeRequestInit event will be refactored in a near future, and a new way to programmatically change the masterpage will be introduced. In the meantime, you can't do it through BeforeRequestInit anymore, this is issue http://issues.umbraco.org/issue/U4-1149. But there is a workaround. You have to do:

    void HandleAfterRequestInit(object sender, RequestInitEventArgs eventArgs)
    {
    int id = GetMyTemplateId();
    var t = template.GetMasterPageName(id);
    Page.MasterPageFile = t;
    }

    Stephan

  • Braydie 148 posts 346 karma points
    Nov 19, 2012 @ 10:43
    Braydie
    0

    Hi Stephan,

    Thanks for your reply, I've got it all working again now! Thanks!

    Braydie

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies