Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Aug 15, 2017 @ 06:02
    Tom
    0

    What replaces Access.HasAccces(<NodeID>,<MemberID>)

    Hi just wondering what replaces Access.HasAccces(

    I'm doing an upgrade from 4->7 and it is deprecated and I'd like to know how to query access for an arbitrary member id thanks :)

  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Aug 15, 2017 @ 08:41
    Kevin Jump
    100

    Hi

    there is an umbraco helper method you can use in views

    Umbraco.MemberHasAccess(path)
    

    but if you want to do it for named users - you need to use the PublicAccessService.

    PublicAccessService.HasAccess(path, GetCurrentMember(), Roles.Provider);
    

    as an example.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Umbraco.Core.Services
    @{ 
        var memberId = 1;
        var member = Membership.GetUser(memberId);
        var access = ApplicationContext.Services.PublicAccessService.HasAccess(Model.Path, member, Roles.Provider);
    }
    

    Ordinarily advice is you should avoid using the services in views, but this is all the MemberHasAccess helper actually does.

    I would also wrap this in some helper code, it doesn't seem very neat to leave in a razor view.

Please Sign in or register to post replies

Write your reply to:

Draft