Copied to clipboard

Flag this post as spam?

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


  • MK 429 posts 906 karma points
    Mar 13, 2012 @ 08:24
    MK
    0

    Check if user/member HasAccess...

    Hi there, 

    Im trying to see if user has access. The only way I fund is as follow:

    Roles.IsUserInRole("Supplier")

    Is there a better way than this?

    Cheers

    mkariti

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 13, 2012 @ 09:29
    Michael Latouche
    0

    Hi mkariti,

    This is indeed the default way of doing, using the default membership provider functionalities.

    Is there a specific reason why you would to do it in another/better way?

    Cheers,

    Michael.

  • MK 429 posts 906 karma points
    Mar 13, 2012 @ 09:41
    MK
    0

    Hi Michael,

    No that is fine! Just checking that Im doing right!

    Many thanks for your quick reply!

    Cheers,

    mkariti

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 13, 2012 @ 10:03
    Michael Latouche
    0

    Hi mkariti,

    You're welcome. And you're indeed doing it right :-) This is one of the many things I like about Umbraco, that you can use the default .Net membership provider to manage security/access.

    Cheers,

    Michael.

  • Yarik Goldvarg 35 posts 84 karma points
    Mar 13, 2012 @ 15:18
    Yarik Goldvarg
    0

    Hi Mkariti

    Try this example

     

    @foreach(var item in Model.Children)

    {

        if(item.HasAccess())

        {

            @item.Name 

        }

    }

     

    Yarik.

  • MK 429 posts 906 karma points
    Mar 13, 2012 @ 19:12
    MK
    0

    Wow many thanks Yarik!

    Works like a charm!

  • Rodion Novoselov 694 posts 859 karma points
    Mar 15, 2012 @ 07:35
    Rodion Novoselov
    0

    Hi. Using the HasAccess property this way keep in mind that there could be some performance issues in case there're lots of child nodes. (By implementation this property queries the database every time being called).

    http://our.umbraco.org/forum/core/general/29722-Lot's-of-SQL-queries

  • MK 429 posts 906 karma points
    Mar 15, 2012 @ 11:20
    MK
    0

    Hi Rodion Novoselov,

    Many thanks for the heads up!

    Any idea on should I implement the HasAccess to check if a member indeed has access to view the item?

    Cheers

    mkariti

  • Rodion Novoselov 694 posts 859 karma points
    Mar 15, 2012 @ 21:25
    Rodion Novoselov
    0

    Hi. Actually I cannot offer the best and only solution for this case at once. Personally right now I'm up to the site that's going to be intended primarily for using by registered members and I feel like the performance can become an issue under load. I haven't yet done any research on it like load tests or like that, but I suppose we will always be able just to wrap the umbraco membership provider with a custom implementation that adds some caching in case we get performace problems with membership.

  • Uranday 32 posts 53 karma points
    Apr 09, 2012 @ 13:29
    Uranday
    0

    About the HasAccess. I tried in V5.1 this code with HasAccess as method and as property, but I can't get it to work. Am I doing something wrong?

    @inheritsRenderViewPage
    @usingUmbraco.Cms.Web;

     
    @{
         
    varHomepage=@DynamicModel;
         
    while(Homepage.ContentType.Alias!="homePage")
         
    {
             
    Homepage=Homepage.Parent;
         
    }
     
    }
     
    <ul>
         
    <li><a href="@Homepage.Url">Home</a></li>
     
    @foreach(var item inHomepage.Children){
         
    if(!item.IsProtected||(item.IsProtected&& item.HasAccess)){
             
    if(@item.CurrentTemplate!=null){
                 
    var childName = item.Name??"(No name yet)";
                 
    <li><a href="@item.Url">@childName</a></li>
             
    }
         
    }
     
    }
     
    </ul>
  • Uranday 32 posts 53 karma points
    Apr 26, 2012 @ 19:52
Please Sign in or register to post replies

Write your reply to:

Draft