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.
Next, modify the controller action that handles the retrieval of content from Kentico:
Open your MVC project, and navigate to the controller that retrieves page content.
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();
- 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).