Current User

James Mosquito asked on November 18, 2020 17:19

Hi, I need to get the current user from a different controller than the one where authentication takes place. I tried a couple of options but both contain anonymous data upon inspection:

- MembershipContext.AuthenticatedUser - Returns Public Anonymous User
- HttpContext.GetOwinContext()?.Get<UserManager>()?.FindByName(User.Identity.Name); - User.Identity is Anonymous

Can I easily achieve this or should I look at some other approach e.g. sharing the user through the property of an abstract controller?

Recent Answers


David te Kloese answered on December 10, 2020 09:37

Did you mange to solve this? If so could you share your solution for future reference?

0 votesVote for this answer Mark as a Correct answer

James Mosquito answered on December 10, 2020 12:15 (last edited on December 10, 2020 12:24)

Hi David,

Yes, it turns out that both of the snippets in my original post work fine in controllers by default. In my case, I was trying to render PageBuilder content from one Page into another by creating my own controller and requestcontext and therefore those methods were not available.

The solution to that was to get the UserId from a controller further up the chain, pass that to my controller through a model/method parameter and finally retrieve the user details from the UserInfoProvider methods.

Thanks, James

0 votesVote for this answer Mark as a Correct answer

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