Is there no native way of getting access to the current user in umbraco 9?
I am currently upgrading a plugin from Umbraco 8 - 9 and in the old code the user was fetched like this:
using Umbraco.Web.Composing;
var user = Current.UmbracoContext.Security.CurrentUser;
this dosnt work in .NET 6.0, atleast i couldnt make it work for some reason, does anyone know where this have been moved? or what i can use to get a similar effect?
Umbraco 9 Get current user?
Hey community,
Is there no native way of getting access to the current user in umbraco 9? I am currently upgrading a plugin from Umbraco 8 - 9 and in the old code the user was fetched like this:
this dosnt work in .NET 6.0, atleast i couldnt make it work for some reason, does anyone know where this have been moved? or what i can use to get a similar effect?
Hey,
So v9 is 100% DI. So "Current", I don't believe, is available at all.
What you need to do is inject in
IBackOfficeSecurityAccessor
then off of that you can callbackOfficeSecurity.BackOfficeSecurity.CurrentUser
You can see this in action here: https://github.com/NikRimington/HotChilli.Umbraco.PageNotFoundManager/blob/fbb2e9d7e1e3003d8feda776b7fd2e792e9737b9/src/HC.PageNotFoundManager.Core/Backoffice/MenuRenderingNotificationHandler.cs#L33
Hope that helps :-)
Nik
i have same issue in umbraco 12 i can't get current user
is working on a reply...