Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
In my DocType i have a property by the name of "membersOnly" (true/false).
When checked, i want to check, if the user is logged in, if not, redirect to login page with a refere.
But what is the best way to do this - i dont want to have in my Master template. How can i hook into the request pipeline, check if the "membersOnly" field excist, and if it does, and it is checked, and the user is not logged in, redirect the user?
Any short snippets out there?
Perhaps you would consider using the default page protection provided by Umbraco. Its based on a custom ASP.Net membership provider and offers you a lot of the functionality you need right out of the box.
Thx for your reply.
I forgot to mention, that in this case, it is by design, that i am not using the built-in way of doing the same thing in the UI. The reason beeing, that the client, wants a simple way of protecting a simple page, without selecting member groups, login page and error page. It has to be a checkbox-option.
How about using your own controller for the page types you want to protect, then you can access that information in the controller and direct to a login page from there?
It depends a little on your strategy for implementing your site, as Marshall suggests you can use your own Controller for Document Types that need to be protected, using 'Route Hijacking' and perhaps a custom Authorise Attribute, so you are not repeating the logic in lots of different hijacked controllers.
If you are not hijacking controllers, you can replace Umbracos 'default' RenderMvcController implementation globally:
and have your logic in your custom controller, and Umbraco will use this to process for all requests...
... and finally... if you don't want to be playing around with controllers, or it would be complex to do so in your solution, there is also an Event called the PublishedContentRequest.Prepared event, that is fired just before Umbraco is considering rendering the page, so this would also be a convenient place, to handle the event, check the logged in status, and the protected checkbox, and redirect unauthorised visitors...
A very interesting aspected connected to the following message. Thanks for sharing! Will be happy to work with it further.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted