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
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);
}
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With