Copied to clipboard

Flag this post as spam?

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


  • Vanlop Incham 4 posts 24 karma points
    Oct 26, 2020 @ 06:45
    Vanlop Incham
    0

    How can I know the current User ID, User Email, or User Name for Umbraco Backoffice User Login?

    Hi Everyone,

    I need to know the information of the current Umbraco back office user is logging in, I need to know the group information indeed.

    Now, I can know only, whether user is logging in or not. But, I don't know any other information of this user:

      var ticket = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
      bool userLoggedIn = ticket != null;
    

    I've an example code to retrieve a group information already. But, I don't know any information for current logging in user, such as email, id, or name to retrieve a group information from them.

    I use these code to retrieve a user information including group information :

    https://our.umbraco.com/Documentation/Reference/Management/Services/UserService/Get-a-reference-to-a-user

    But, it needs Id, Username, or Email of the user. So, how can I known the current Umbraco back office that logging in.

    Thank you

  • Corné Strijkert 80 posts 456 karma points c-trib
    Oct 26, 2020 @ 20:59
    Corné Strijkert
    0

    You can access the current backoffice user with:

    Current.UmbracoContext.Security.CurrentUser
    

    Or with:

    using (var contextReference = _contextFactory.EnsureUmbracoContext())
    {
        var user = contextReference.UmbracoContext.Security.CurrentUser;
    }
    
  • Vanlop Incham 4 posts 24 karma points
    Apr 07, 2021 @ 20:38
    Vanlop Incham
    0

    Thanks for your reply. But, I got an error.

    var umUser = Current.UmbracoContext.Security.CurrentUser;
    
    
    >     Compiler Error Message: CS0103: The name 'Current' does not exist in the current context
    

    and

    var contextReference = _contextFactory.EnsureUmbracoContext();
    var umUser = contextReference.UmbracoContext.Security.CurrentUser;
    
    
    >     Compiler Error Message: CS0103: The name '_contextFactory' does not exist in the current context
    

    I used it in .cshtml file. How can I reference to contextFactory or Current context. I use Umbraco version 8.6.3.

    Could you show me an example for only display the current username that logging in umbraco Backoffice. Look like this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Umbraco.Web.Security
    @{
        var ticket = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
        bool userLoggedIn = ticket != null;
    
        //var umUser = Current.UmbracoContext.Security.CurrentUser;
    
        var contextReference = _contextFactory.EnsureUmbracoContext();
        var umUser = contextReference.UmbracoContext.Security.CurrentUser;
    }
    Logged in = @userLoggedIn<br>
    Username = @umUser<br>
    

    Thanks a lot.

  • fatmazayed 41 posts 123 karma points
    Oct 17, 2023 @ 21:57
    fatmazayed
    0

    @Vanlop Incham i got the same error iam using umbraco 12

  • 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