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.
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?
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?
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
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?
Wrap you macro's in a if statement checking if a user is logged in with this function : umbraco.library.IsLoggedOn()
Dave
You can also use:
is working on a reply...