Check if user is authenticated on Kentico MVC

Gustavo Quevedo asked on February 24, 2020 16:18

Hi,

I'm trying to check if the current user is authenticated in the CMS on an MVC application as I used to do with Portal Engine:

CMS.Membership.AuthenticationHelper.IsAuthenticated()

This doesn't seem to work on MVC and I guess the reason has to do with the fact that the CMS is now a separate application.

Is there any other way to check this from the application code? Maybe checking the content of the .ASPXFORMSAUTH cookie?

Thank you in advance!

Gustavo

Recent Answers


Brenden Kehren answered on February 24, 2020 16:29

Have you checked the documentation for authentication within Kentico and MVC yet?

0 votesVote for this answer Mark as a Correct answer

Gustavo Quevedo answered on February 24, 2020 18:06 (last edited on February 24, 2020 19:31)

@Brenden Thanks for your message.

Yes, I already tried that also having implemented the code in the previous section: Integrating Kentico membership into your project

Apparently I can sign in (I got success) and sign out with that code.

However, I always get false when I check if the user is authenticated, even if I sign in programatically. But note that my MVC application doesn't allow authentication, just the CMS application does via the login form.

I've checked the authentication the ways below and all of them returned false:

User.Identity.IsAuthenticated

HttpContext.GetOwinContext().Authentication.User.Identity.IsAuthenticated

CMS.Membership.AuthenticationHelper.IsAuthenticated()

Any idea about what I'm doing wrong?

Thank you

Kind regards,

Gustavo

0 votesVote for this answer Mark as a Correct answer

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