Copied to clipboard

Flag this post as spam?

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


  • Garðar Þorsteinsson 113 posts 534 karma points
    Jan 18, 2015 @ 00:22
    Garðar Þorsteinsson
    0

    Get Backend User when member is logged in

    Hi,

    I have been trying to get current backend user and current member user logged in when they both are logged in but when ever the member is logged in the backend user is always returned as null.

    I have tried few of the options I know that get the backend user, f.ex : UmbracoContext.Current.Security.CurrentUser,umbraco.BusinessLogic.User.GetCurrent() and umbraco.helper.GetCurrentUmbracoUser().

    All return null when member is logged in.

    I suspect that they are using the same authentication in the .net membership so the member always overrides the umbraco user.

    Has anybody managed to get both users at the same time when they are logged in ?

     

     

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 19, 2015 @ 17:23
    Dan Lister
    0

    Hi Garðar,

    What version of Umbraco are you using? Both use different membership providers.

    You should be able to get the current Member by using Membership.GetUser().

    var memberName = Membership.GetUser().UserName;
    var member = ApplicationContext.Services.MemberService.GetByUsername(memberName);
    

    You should be able to get the current back office User by using UmbracoContext.Security.CurrentUser:

    Hope that helps.

    Thanks, Dan.

  • Roman 2 posts 27 karma points
    Jan 22, 2015 @ 08:10
    Roman
    5

    That was my problem too. I found the way though. We can get current user by a method like this:

    public static IUser GetCurrentUser()
    {
    var userName = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket().Name;
    return ApplicationContext.Current.Services.UserService.GetByUsername(userName);
    }

    You'll want some usings also:

    using Umbraco.Core;
    using Umbraco.Core.Models.Membership;
    using Umbraco.Core.Security;
Please Sign in or register to post replies

Write your reply to:

Draft