SiteContext.CurrentUser vs MembershipContext.AuthenticatedUser

Matthew Lee asked on November 8, 2015 23:54

Hi,

I have a question request to these two classes

  1. SiteContext.CurrentUser
  2. MembershipContext.AuthenticatedUser

Basically, I added a LogOnForm webpart (Out of the box in Kentico) in a page and logged in through this page. I found that the SuteContext.CurrentUser return null and MembershipContext.AuthenticatedUser return me a correct user. I was wondering do I use MembershipContext.AuthenticatedUser all the time or under what situation I would useSiteContext.CurrentUser?

Should I add a line to set the SiteContext.CurrentUser = MembershipContext.AuthenticatedUser in the webpart?

Recent Answers


David te Kloese answered on November 9, 2015 01:45

Hi,

You should use MembershipContext.AuthenticatedUser!

SiteContext.CurrentUser

It is available when the request contains parameters "userid", "username" or "userguid" with valid value of the user.

https://devnet.kentico.com/docs/8_2/api/html/P_CMS_SiteProvider_SiteContext_CurrentUser.htm

So MembershipContext.AuthenticatedUser is an actual logged-on user, where as the other can be manipulated by url parameters.

Greets,

David

4 votesVote for this answer Mark as a Correct answer

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