Copied to clipboard

Flag this post as spam?

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


  • Sten Hougaard 12 posts 84 karma points
    Sep 04, 2015 @ 07:03
    Sten Hougaard
    0

    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

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 04, 2015 @ 07:43
    Dennis Aaen
    101

    Hi Sten,

    Could you use some like this example?

    @foreach (var child in CurrentPage.Children) { 
        <h2>@child.Name</h2>
            @if(Umbraco.IsProtected(child.id, child.Path)){
                <blink>Members only</blink>
            }
    }
    

    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

  • Sten Hougaard 12 posts 84 karma points
    Sep 04, 2015 @ 08:19
    Sten Hougaard
    0

    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

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 04, 2015 @ 08:31
    Dennis Aaen
    1

    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.

    enter image description here

    I also think that this blogpost can help you http://goo.gl/AjSRze

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft