Copied to clipboard

Flag this post as spam?

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


  • Arun 136 posts 369 karma points
    Nov 25, 2022 @ 11:27
    Arun
    0

    Check a node is Public Access Restricted or not

    Hi Team,

    I need to display some nodes on the Website header menu,
    but before that, I have to check if that node is restricted from public access or not.
    Is it possible to check that from partial view?

    The scenario is like this, based on member group permission, I have set Restrict Public Access for certain nodes.

    When someone goes to the site, they should not be able to see the protected page but if that user is already logged in then he should be able to see those items in the menu.

    Regards

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Nov 25, 2022 @ 11:33
    Huw Reddick
    0

    you should be able to use

    .Where(x=>x.IsVisible());
    

    If the restriction is more granular (some members can see it) you can use

    _memberManager.MemberHasAccessAsync(content.Path).Result
    
  • Arun 136 posts 369 karma points
    Nov 25, 2022 @ 12:24
    Arun
    0

    Hi Huw,

    Thanks for your time :)
    IsVisible is used for the umbracoNaviHide field right?

    My concern is different, based on member group permission, I have set Restrict Public Access for certain nodes.

    When someone goes to the site, they should not be able to see the protected page but if that user is already logged in then he should be able to see those items in the menu.

    Thank you

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Nov 25, 2022 @ 13:24
    Huw Reddick
    0

    You will need to use IMemberManager and do something like

    @{
        var selection = Umbraco.ContentAtRoot().FirstOrDefault()
            .Children().Where(x => x.IsVisible());
    }
    <!-- Navigation -->
    <div class="container">
        <nav class="navbar navbar-expand navbar-light">
            <!-- Links -->
            <ul class="navbar-nav">
                @foreach (var item in selection)
                {
                    if (_memberManager.MemberHasAccessAsync(item.Path).Result)
                    {
                    <li class="nav-item">
                        <a href="@item.Url()" class="nav-link" >@item.Name()</a>
                    </li>
                    }
    
                }
            </ul>
    
        </nav>
    </div>
    
Please Sign in or register to post replies

Write your reply to:

Draft