Check permission on unauthenticated user

Victor G asked on May 18, 2015 14:34

Hi

I'm trying to check if an unauthenticated user is allowed to access a certain page (document). I've found a way to check it here: https://docs.kentico.com/display/K81/Checking+permissions+using+the+API

The problem is that when the user is not logged in, the "CheckPermissions" method throws an "CMS.DataEngine.PermissionCheckException". Is this a bug? Or is there another way to check if the user is allowed on a certain page?

Thanks

Best, Victor

Correct Answer

Petar Kozjak answered on May 19, 2015 12:21

Hi,

I did read your post. Still not sure do I understand.

But if you want to check is page set for "Requires Authentication" maybe you can use code like this on a page: PageInfoProvider.GetPageInfo(DocumentContext.CurrentDocument.DocumentGUID).RequiresAuthentication;

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 18, 2015 14:42

Guess I've never taken this approach before. I've always just assigned permissions to users in roles. I don't believe you'll get to assign any permissions to a non-authenticated user or role because you can't really check that.

What I'd test is assign permissions to the "Public" user then check if the user is the public user OR not authenticated OR if the user is Public and assigned the role(s) you specify and then perform you actions. Not saying it will work but its worth a test.

0 votesVote for this answer Mark as a Correct answer

Victor G answered on May 18, 2015 15:09

Hi Brenden,

Thanks for the quick answer. I think you misunderstood me. Let me try again. Let's suppose we have the following situation: a Kentico site with 5 pages -> 2 of this pages are visible just for logged in users (in Pages-> Security -> Requires authentication is set to true). Now I want to check in code if the current page is visible just for the logged in users or for everyone in other words if the "Requires authentication" is set to true or false.

Thanks

Best, Victor

0 votesVote for this answer Mark as a Correct answer

Petar Kozjak answered on May 18, 2015 19:40

Hi,

why no just use MembershipContext.AuthenticatedUser to check if user is authenticated?

0 votesVote for this answer Mark as a Correct answer

Victor G answered on May 19, 2015 09:20

Hi Petar,

Did you even read my post? I don't need to check if the user is authenticated or not. I need to check if a certain page (document) is allowed to be accessed without authentication.

Best, Victor

0 votesVote for this answer Mark as a Correct answer

Victor G answered on May 19, 2015 13:03

Hi Petar,

This is exactly what i need! Thanks!

Best, Victor

0 votesVote for this answer Mark as a Correct answer

Paul Ryan answered on November 18, 2016 20:31

Where's the answer???

This thread goes from Victor asking "Did you even read my post?" to the next message where he says "This is exactly what i need! Thanks!".

What was the code that resolved his issue?

0 votesVote for this answer Mark as a Correct answer

Paul Cripps answered on January 24, 2017 16:06

Same question as Paul Ryan. Where is the answer to this issue?

0 votesVote for this answer Mark as a Correct answer

Victor G answered on January 24, 2017 16:19

Please check the date of the replies! The correct answer was marked as "Correct Answer":

PageInfoProvider.GetPageInfo(DocumentContext.CurrentDocument.DocumentGUID).RequiresAuthentication;
0 votesVote for this answer Mark as a Correct answer

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