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

Forums / Security / Check page permission for a specific role from code

Check page permission for a specific role from code

2 posts, 0 answered
  1. Guyso
    Guyso avatar
    3 posts
    Registered:
    02 Jan 2009
    15 Feb 2010
    Link to this post
    Hallo Telerik Team,

    I would like to check a page permission for a specific role (not the current User roles) from code, 

    PagePermission.CheckDemand(PageRights) functions only with the current User Roles

    thank you

    Guyso

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Feb 2010
    Link to this post
    Hello Guyso,

    You can use the SecurityManager and cast the ICmsPage to ISecured object. Then you can get all permissions and using logical operations check for particular permissions:
    //get permsissions for secured object for all roles in default provider
    IList permissions = cmsManager.SecurityManager.GetPermissions((ISecured)page);
    foreach (Permission permission in permissions)
    {
        int grant = permission.Grant;
        grant |= PageRights.Delete;
        if (permission.Grant == grant)
        {
     
        }
    }
    //get permission for particlular role from particular provider
    IAccessPermisson accessPermission = cmsManager.SecurityManager.GetPermission((ISecured)page, "Sitefinity", "test");
    int deny = accessPermission.Deny;
    deny |= PageRights.View;
    if (accessPermission.Deny == deny)
    {
        //means that the View permission is set to deny for this role for particular page
    }

    Kind regards,
    Radoslav Georgiev
    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