Copied to clipboard

Flag this post as spam?

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


  • Allan Koch 9 posts 23 karma points
    Apr 08, 2013 @ 13:44
    Allan Koch
    0

    How to prevent Macros with Razor being rendered?

    Hi guys and gals,

    I have a question regarding how to prevent Macro's from being rendered. The setup is this:

    On my master page, in the Page_Load, I have some checks to determine if a user is logged in or not.

    If the user is not logged in, I want to redirect the user to a specific page.

    Because of the mechanics with Response.Redirect the redirect doesn't happens immediately, and so the page starts rendering the macro's on a given page.

    The page contains macro's with Razor files, which tries to open connections to some web services in it's markup. These services requires that the user is logged in, so the services then starts throwing exceptions.

    The user doesn't see this. He is just redirected, but the services logs all these exceptions, and over time they amount to many thousand exceptions.

     

    So.... I'm looking for a way to hook in somewhere and prevent rendering macro's given some specific circumstances.

     

    Does anyone know of how this can be achieved?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 14:02
    Dave Woestenborghs
    0

    You can check if a user is logged in with this function : umbraco.library.IsLoggedOn()

    Also Response.Redirect has a parameter to stop the response. So the rest of the page doesn't get rendered.

    http://msdn.microsoft.com/en-us/library/a8wa7sdt.aspx

    Dave

  • Allan Koch 9 posts 23 karma points
    Apr 08, 2013 @ 14:53
    Allan Koch
    0

    Hi Dave,

    Thanks for the quick response. 

    I have tried using the true parameter with Reponse.Redirect, but it still doesn't stop the response immediately and the macro's are still being fired, causing the razor-macro's to throw exceptions. (although they are not being shown).

    Im not entirely sure what happens, maybe something with the macros being processed in different threads. But the exceptions from the razor files are thrown.

    Plenty of others have this issue, and its not Umbraco related. Google on: response.redirect does not work.

     

    But response.redirect isn't really the question:

    What I really want to do is prevent Umbraco from processing macro's unless the user is logged in. How would I achieve that?

     

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 14:54
    Dave Woestenborghs
    0

    Wrap you macro's in a if statement checking if a user is logged in with this function : umbraco.library.IsLoggedOn()

    Dave

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Apr 08, 2013 @ 21:34
    Dan Diplo
    0

    You can also use:

    if (User.Identity.IsAuthenticated) {
       // your macro code
    }
Please Sign in or register to post replies

Write your reply to:

Draft