Check authentication of page Kentico 12

Sukh kumar asked on November 24, 2020 17:51

My requirement is to validate the page if it requires authentication. If the user is of role Global Admin and page does not require authentication then anyone can view the page, otherwise user will be redirected to login page.

I am setting the authentication from the "Security" tab.

I am using below code to check the authentication of page

var requiresAuthentication = CMS.DocumentEngine.PageInfoProvider.GetPageInfo(CMS.SiteProvider.SiteContext.CurrentSiteName , Model.Page.NodeAliasPath, "en-US", Model.Page.AbsoluteURL, false);

But it always returns null.

And to check the role I am using below code

CMS.Membership.MembershipContext.AuthenticatedUser.IsInRole("GlobalAdmin" ,CMS.SiteProvider.SiteContext.CurrentSiteName)

Thanks in advance

Recent Answers


Brenden Kehren answered on November 24, 2020 22:07

I'm not sure how you can accomplish this as you can't check roles unless a person is logged in. So in order to properly check, everyone would need to be authenticated first.

0 votesVote for this answer Mark as a Correct answer

Sukh kumar answered on November 25, 2020 07:58 (last edited on November 25, 2020 10:30)

Thanks for reply Brenden

I might have not mentioned the complete scenario.

  • I have created a generic page template. And in CMSDesk I am creating pages using that. So while on front-end we have no use of role. But in CMSDesk when Global Admin is logged in then we will show the content only for that role otherwise login page will display instead of page content.

So I dropped the idea of roles instead I can check privilege level of the logged in user in CMSDesk. Thanks

  1. Also not able to get the page authentication value with the below code. What's you take on this. It always returns null. Am I missing something or it is depreciated. I haven't found much on this

var requiresAuthentication = CMS.DocumentEngine.PageInfoProvider.GetPageInfo(CMS.SiteProvider.SiteContext.CurrentSiteName , Model.Page.NodeAliasPath, "en-US", Model.Page.AbsoluteURL, false);

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on November 25, 2020 11:52

What is always null? Are you using MVC or Portal engine? Where are you running the code? The page object has the IsSecuredNode property (column in CMS_Tree) telling whether it requires authentication or not. I just tried something like described here - but instead of setting the value, I read it. Keep in mind that GetPageInfo may not always return all the properties.

0 votesVote for this answer Mark as a Correct answer

Sukh kumar answered on November 25, 2020 12:45 (last edited on November 25, 2020 12:59)

Hi Juraj,

I am using MVC. I have registered a page template in PageBuilderComponentRegister.cs. No controller is used so I am trying to fetch the page info on the view. Below is my code


var pageInfo = CMS.DocumentEngine.PageInfoProvider.GetPageInfo(SiteContext.CurrentSiteName , Model.Page.NodeAliasPath, preferredCultureCode, Model.Page.NodeAliasPath, false); // RequiresAuthentication;


The "Model.Page" is not null and has all the values which I used in the above method.

The "GetPageInfo" method returns one property "RequiresAuthentication" which I need to check whether page needs authentication or not. The "RequiresAuthentication" property value is set in "Security" tab of the page in CMSDesk.

I am getting "pageInfo" variable always null. That is the issue.

I don't know what I am missing

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.