Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current user in Umbraco version 7.3.5

I'm trying to access the logged in Umbraco User, not member, but I cant get it work.

I have tried with the following methods but none work, they all return null:

umbraco.BusinessLogic.User.GetCurrent()
UmbracoContext.UmbracoUser
UmbracoContext.Security.CurrentUser
umbraco.helper.GetCurrentUmbracoUser()

I can access the user, for example Name, with the code below:

UmbracoContext.Application.Services.UserService.GetByEmail("[email protected]").Name

I have tried this code being logged in as a user and member, only user, only member and not logged in at all and it always returns the same result, null.

I have tried the code in a SurfaceController and UmbracoApiController with the same result. There is no problem getting the logged in member with Membership.GetUser(); Has anyone else experienced this?

Using: Umbraco version 7.3.5 assembly: 1.0.5858.25602

like image 650
Ogglas Avatar asked Feb 12 '16 13:02

Ogglas


2 Answers

Yeah I've tried to access the current backend user in numerous ways before and found the only way is to do:

var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
if (userTicket != null)
{
    var currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);
}
like image 97
Ryan McDonough Avatar answered Nov 19 '22 17:11

Ryan McDonough


I have just yesterday implemented some code to get the current user using:

UmbracoContext.Current.Security.CurrentUser

That is not listed as one of the options you have tried?

like image 33
ProNotion Avatar answered Nov 19 '22 18:11

ProNotion