Copied to clipboard

Flag this post as spam?

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


  • Jan Molbech 40 posts 126 karma points
    Jul 02, 2014 @ 10:21
    Jan Molbech
    0

    How to get logged in member?

    There isn't a method in the MemberService that get's me the current logged in member.

    The MembershipHelper.GetCurrentMember returns a member in a format (IPublishedContent) which i don't know how to use and can't convert to IMember which the MemberService is using.

    What is the best way to get the current logged in member?

  • Dan Lister 416 posts 1974 karma points c-trib
    Jul 02, 2014 @ 12:18
    Dan Lister
    0

    Hi Jan,

    You can either use the built in .NET Membership provider method:

    Membership.GetUser() 
    

    Or the old way using:

    umbraco.cms.businesslogic.member.Member.GetCurrentMember()
    

    Thanks, Dan.

  • Jan Molbech 40 posts 126 karma points
    Jul 02, 2014 @ 12:56
    Jan Molbech
    0

    But then the problem arises when you want to use the new MembershipService together with the "old" type of umbraco member since they are not the same type.

    How do I convert the old type to IMember?

  • Dan Lister 416 posts 1974 karma points c-trib
    Jul 02, 2014 @ 14:26
    Dan Lister
    5

    I don't think there is way to convert between the two without first obtaining the Member ID you wish to convert. You could try the following:

    var oldMember = umbraco.cms.businesslogic.member.Member.GetCurrentMember();
    var newMember = ApplicationContext.Services.MemberService.GetById(oldMember.Id);
    

    If you were to only use the new services, to find the current Member you could use the following:

    var username = Membership.GetUser().UserName;
    var member = ApplicationContext.Services.MemberService.GetByUsername(username);
    
  • Barry Fogarty 493 posts 1129 karma points
    Jun 02, 2016 @ 13:46
    Barry Fogarty
    2

    For the benefit of future searchers, you are able to get

    (MemberPublishedContent)Members.GetCurrentMember();
    

    Which returns a read-only object like IPublishedContent, but with the other member-specific properties too (Username, Email, IsApproved etc).

    You'll still need to use the MemberService to save data but this is a handy cast for display purposes.

  • 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