Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • NoPainNullGain 1 post 22 karma points
    Mar 16, 2022 @ 09:24
    NoPainNullGain
    1

    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:

    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?

  • Nik 1625 posts 7295 karma points MVP 8x c-trib
    Mar 16, 2022 @ 10:46
    Nik
    1

    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 call backOfficeSecurity.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

  • fatmazayed 41 posts 123 karma points
    Oct 17, 2023 @ 22:34
    fatmazayed
    0

    i have same issue in umbraco 12 i can't get current user

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies