Copied to clipboard

Flag this post as spam?

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


  • Filipe Sousa 39 posts 170 karma points
    Jan 28, 2020 @ 18:13
    Filipe Sousa
    0

    Get current user

    Hi there,

    how do I get the current user within a DelegatingHandler when loading a page in the backoffice?

    I'm injecting the IUmbracoContextFactory and fetching the user like so, but it's always null.

    using (var contextReference = _umbracoContextFactory.EnsureUmbracoContext())
            {
                var user = contextReference.UmbracoContext.Security.CurrentUser;
            }
    

    Much appreciated.

  • Ruben Meintema 9 posts 100 karma points
    Apr 22, 2020 @ 12:56
    Ruben Meintema
    0

    Hi Filipe,

    On the frontend of the website the user would be null, in the Umbraco backoffice you would be able to get a proper user.

    Cheers, Ruben

  • Pagggy 27 posts 46 karma points
    Apr 22, 2020 @ 13:14
    Pagggy
    0

    Hi @Filipe Sousa, how did you managed to add DelegatingHandler in umbraco 8. I am struggling to migrate my code from v7 to v8 for custom delegatinghandler.

  • Ruben Meintema 9 posts 100 karma points
    Apr 23, 2020 @ 07:31
    Ruben Meintema
    0

    Hi @Filipe Sousa,

    There is also a difference between trying to a User (an Umbraco CMS user) and a Member (like a user that is logged in to the frontend of the website). The former will not be resolved with "contextReference.UmbracoContext.Security.CurrentUser", while the latter can be resolved like this.

    Cheers, Ruben

  • Enkosi 8 posts 80 karma points
    Dec 17, 2020 @ 07:11
    Enkosi
    1

    Filipe, you can try the following to get the current user:

    var wrapper = new HttpContextWrapper(HttpContext.Current);
    var currentUserObj = wrapper.GetCurrentIdentity(true);
    

    Hope it helps.

  • 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