Copied to clipboard

Flag this post as spam?

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


  • Luke 110 posts 256 karma points
    Jan 06, 2015 @ 14:44
    Luke
    0

    Getting Current Backend User

    Hi All,

    I am trying to get the logged in backoffice user. I have used the code below but it seems to work in some instances but not all.

    var userService = Umbraco.Core.ApplicationContext.Current.Services.UserService;
    return userService.GetByUsername(HttpContext.Current.User.Identity.Name);
    

    To slightly complicate matters a backoffice user may also be logged in as a member at the sametime.

    Any help would be appreciated!

    Regards L

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 06, 2015 @ 15:35
    Lee Kelleher
    1

    Hi L,

    Try using UmbracoContext.Current.Security.CurrentUser to get the current back-office user.

    Cheers,
    - Lee

  • Luke 110 posts 256 karma points
    Jan 07, 2015 @ 08:41
    Luke
    0

    Hi Lee,

    That seems to be working, thank you kindly!

    Regards, L

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 07, 2015 @ 11:58
    Lee Kelleher
    0

    You're welcome. Don't forget to mark the solution, (it helps others for future reference).

    Thanks,
    - Lee

  • Luke 110 posts 256 karma points
    Jan 08, 2015 @ 09:25
    Luke
    0

    Hiya

    Interestingly this does not work again in all instances. This still returns null when calling from a user control that is used in the backoffice. However it does work in other scenarios.

    Any ideas why? or other solutions?

    Regards, L

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 08, 2015 @ 14:23
    Lee Kelleher
    0

    Hi L,

    Does your user-control inherit from Umbraco.Web.UI.Controls.UmbracoUserControl?

    If so, then you should be able to use Security.CurrentUser directly.

    Cheers,
    - Lee

  • Luke 110 posts 256 karma points
    Jan 08, 2015 @ 17:02
    Luke
    0

    Actually I was just inheriting System.Web.UI.UserControl Would it be bestr to inherit Umbraco.Web.UI.Controls.UmbracoUserControl?

    Thank you for your help, Regards L

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 08, 2015 @ 17:10
    Lee Kelleher
    0

    If you inherit from Umbraco.Web.UI.Controls.UmbracoUserControl instead, it will give you easier ways to access the various service APIs + an instance of UmbracoHelper is available (called "Umbraco").

  • Comment author was deleted

    Nov 25, 2015 @ 15:39

    Connecting an issue here as I eventually ran into a null user from a RenderMVC controller.

    http://issues.umbraco.org/issue/U4-6496

    The link above provides a workaround if needing to know from the frontend if a user is logged into the backoffice or not.

Please Sign in or register to post replies

Write your reply to:

Draft