)

Checking page permissions

You can control which users and roles can view pages on the live site by configuring page-level permissions and extending the document query that retrieves page content with a CheckPermissions call. The method ensures the retrieved collection only contains pages for which the current user has the Read permission.

  1. Open the Pages application and select the page for which you wish to set permissions.
  2. Configure the page's page-level permissions (ACLs).
  3. Click Save.

Next, modify the controller action that handles the retrieval of content from Kentico:

  1. Open your MVC project, and navigate to the controller that retrieves page content.

  2. In the controller action, extend the document query expression by adding the CheckPermissions method. We recommend using provider classes generated by the system to retrieve content from Kentico.

    // Gets the specified articles using the generated provider and checks their page permissions
    IEnumerable<Article> articles = ArticleProvider.GetArticles()
        .OnSite("MySite")
        .Culture("en-US")
        .Path("/Articles/", PathTypeEnum.Children)
        .CheckPermissions();
  3. Build the MVC project.

Only the specified users can now view the content of the page on the live site. Users who do not have the required permission see a page not found error.

Note: By default, the permission matrix is blank for all pages, meaning users are forbidden from all actions (for example, reading or modifying page content).


Was this page helpful?