Copied to clipboard

Flag this post as spam?

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


  • Steve Morgan 1348 posts 4457 karma points c-trib
    Nov 30, 2017 @ 16:38
    Steve Morgan
    0

    Umbraco.IsProtected(curPage.Url) doesn't work?

    Hi,

    Can anyone please confirm that when looping through pages

    Umbraco.IsProtected(curPage.Url) doesn't work?

    but

    Umbraco.IsProtected(curPage.Id, curPage.Url) does (but has been marked as obsolete?).

    If so I'll raise a bug.

    Steve

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 30, 2017 @ 16:43
    Dan Diplo
    0

    Hi Steve,

    I think you need to use this now in latest Umbraco versions:

    Umbraco.MemberHasAccess(curPage.Path)
    
  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 01, 2017 @ 11:28
    Steve Morgan
    0

    Hi,

    I don't believe this works either!

    For a non-logged in user I can see all pages when I loop through.

        @{
        var pages = Model.Content.Children();
    
        foreach (var page in pages)
        {
            if (!Umbraco.MemberHasAccess(page.Url))
            {
                <h1>@page.Url IS PROTECTED</h1>
            }
            else
            {
                <h1>@page.Url</h1>
            }
        }
    
    }
    

    But if you change this to (page.Id, page.Url) it works.

    I've raised an issue:

    http://issues.umbraco.org/issue/U4-10729

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Dec 01, 2017 @ 11:43
    Dan Diplo
    100

    Steve, you have to pass the Path parameter of the IPublishedContent to Umbraco.MemberHasAccess() and not the Url.

    So you would use:

    foreach (var page in pages)
        {
            if (!Umbraco.MemberHasAccess(page.Path))
            {
                <h1>@page.Url IS PROTECTED</h1>
            }
            else
            {
                <h1>@page.Url</h1>
            }
        }
    

    I've used this on a site recently and it did work.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 01, 2017 @ 11:54
    Steve Morgan
    0

    DOH!

    I got totally blindsided by the URL - of course!

    Thanks for the heads up.

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft