I am building a menu where some pages are behind login (protected). On the menu for those pages need to add a login key icon. I am looking for the Razor code which will tell me if a page requires login.
I have chosen simple login by setting Public Access to Single user protection, and added login, password, login page and Error Page. The system replied that the page now is protected, so I guess that the protection has been applied correctly.
I do a "standard" loop where I find pages for the navigation. However as I try to check the protection of the page, these two values are empty:
@childPage.IsProtected - @childPage.hasAccess()
Is there another way where I should check if a page is protected?
And how about the login and error page, which I need to choose as I add Single user protection to the page - how should I construct them?
For the login page you could use the built in template for a login for, there is a Razor snippet for this. For the error page, it could be a simple standard text page where you write some text.
Or you could choose to create a new document type for the error page, if it´s need to have a different look and feel, than some of your other page types that you already has in your content tree.
Perfectly. If you go the developer section, and open up the partial view macro files folder, and right-click to create a new file, then you can choose a starting template, and in the list you will find Login, as a option.
Check if a page requires login
Hi,
I am building a menu where some pages are behind login (protected). On the menu for those pages need to add a login key icon. I am looking for the Razor code which will tell me if a page requires login.
I have chosen simple login by setting
Public Access
to Single user protection, and added login, password, login page and Error Page. The system replied that the page now is protected, so I guess that the protection has been applied correctly.I do a "standard" loop where I find pages for the navigation. However as I try to check the protection of the page, these two values are empty:
@childPage.IsProtected - @childPage.hasAccess()
Is there another way where I should check if a page is protected?
And how about the login and error page, which I need to choose as I add Single user protection to the page - how should I construct them?
/Sten Hougaard
http://www.netsi.dk/wordpress
http://twitter.com/netsi1964
Hi Sten,
Could you use some like this example?
For the login page you could use the built in template for a login for, there is a Razor snippet for this. For the error page, it could be a simple standard text page where you write some text.
Or you could choose to create a new document type for the error page, if it´s need to have a different look and feel, than some of your other page types that you already has in your content tree.
Hope this helps,
/Dennis
Hi Dennis,
The code snippet you supplied to check if the page is protected works perfectly! :-) Thanks!
Could you please advice me where I can read more about the build in login template you mention, and also the Razor snippet.
Thank you!
/Sten
Hi Sten,
Perfectly. If you go the developer section, and open up the partial view macro files folder, and right-click to create a new file, then you can choose a starting template, and in the list you will find Login, as a option.
See this screenshot below.
I also think that this blogpost can help you http://goo.gl/AjSRze
Hope this helps,
/Dennis
is working on a reply...