+1-888-365-2779
Try Now
More in this section

Forums / Security / Check permission for particular role

Check permission for particular role

2 posts, 0 answered
  1. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    06 May 2010
    Link to this post
    I have more that 100 pages on the site and assigned roles. Is that a way to write code to display what roleA has access? Or pageA is assigned to which role? Can someone show me an example code?

    Thanks,
    Pik  
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 May 2010
    Link to this post
    Hi Pik Lee,

    Below is a sample code that shows how to check View permissions for a given role

    IDictionary<string, ApplicationPermission> permissions;
    ISecured secObj = page as ISecured;
       if (secObj is ISecuredBase)
              permissions = ((ISecuredBase)secObj).GetPermissions("Sitefinity");
                else
              permissions = secObj.Permissions;
     
                string[] roles =  { "role1" };        
                foreach (string role in roles)
                    {
                        bool hasPermission = false;
      
                        ApplicationPermission permiss;
                        if(!Telerik.Security.Configuration.ConfigHelper.IsRoleUnrestricted(role))
                        {
                            if (permissions.TryGetValue(role, out permiss))
                            {
                                hasPermission = HasPermission(permiss, PageRights.View);
      
      
                                if (hasPermission)
                                {
                                    Response.Write(role + " "+ " have view" + "<br />");
                                }
                                else
                                {
                                    Response.Write(role + " "+ "does not have view" + "<br />");
                                }
                                 
      
                            }
                        }
                    }
                }

    You could also take a look at this post.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
2 posts, 0 answered