Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity 3.x: Security > Check page permission from code

Check page permission from code

  • Posted on Feb 8, 2010 (permalink)

    Hallo,

    i want to check the permissions for the current page from to allow or deny specific actions for the current user.

    Is it possible to check if the user

    - HasViewPermission(CurrentPage)
    - HasCreatePermission(CurrentPage)
    - HasPublishPermission(CurrentPage)
    - ....

    Thank u

    Guy

    Reply

  • Answer Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 8, 2010 (permalink)

    Hi Guyso,

    Below is a sample code that illustrates how to check the permissions programmatically

    ICmsPage p;
    ISecured sec = p as ISecured;
    PagePermission perm = new PagePermission(sec);
    // check view
    perm.CheckDemand(PageRights.View);
    //check create
    perm.CheckDemand(PageRights.Create);
    perm.CheckDemand(PageRights.Publish);

    You can also use CrudRights.View and CrudRights.Create etc. PageRights class inherits from CrudRights class.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.

    Reply

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity 3.x: Security > Check page permission from code