Copied to clipboard

Flag this post as spam?

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


  • Rob Church 6 posts 51 karma points
    Apr 16, 2014 @ 17:23
    Rob Church
    0

    How to get current member ID in Umbraco 7.1

    At the moment I have code to get the member ID (to store on a different database).

    using umbraco.cms.businesslogic.member;
    ....
    var memberID = Member.CurrentMemberId();
    

    It's throwing a warning:

    warning CS0618: 'umbraco.cms.businesslogic.member.Member' is obsolete: 'Use the MemberService and the Umbraco.Core.Models.Member models instead'

    But the MemberService is about CRUD operations and the Member class doesn't seem to do anything about the currently logged in member. I also found MembershipHelper.GetCurrentLoginStatus() but there's no ID on the returned data.

    Where should I go to get this information now?

  • Masood Afzal 176 posts 522 karma points
    Apr 16, 2014 @ 17:37
    Masood Afzal
    0

    try this:

                var user = Membership.GetUser();

                var userId = (int)user.ProviderUserKey; 

  • Rob Church 6 posts 51 karma points
    Apr 16, 2014 @ 17:45
    Rob Church
    0

    So I should be dropping down to System.Web.Security - there's no Umbraco-y method?

  • Masood Afzal 176 posts 522 karma points
    Apr 16, 2014 @ 17:54
    Masood Afzal
    0

    Yes, .NET Membership

  • Charles Afford 1163 posts 1709 karma points
    Apr 21, 2014 @ 21:04
    Charles Afford
    0

    Yep using the .Net membership is the way.  You can impliment your own MembershipProvider which is usefull

    Just create a class that impliments MembershipProvider.

    You can also use the Umbraco Membership Service.

    Charlie :)

    http://our.umbraco.org/documentation/reference/management-v6/services/MemberService

  • Dan Mothersole 22 posts 109 karma points
    Apr 28, 2014 @ 16:01
    Dan Mothersole
    2

    Use the new API

     

    using Umbraco.Core.Services;

    using Umbraco.Core.Persistence;

    var x = new MemberService( new RepositoryFactory(), new MemberGroupService( new RepositoryFactory()) );

     

    x. - what ever method you want.

    Not 100% sure I newed up the member service properly as I have had no call to use it but I have used the UserSerivce as follows - var x = new UserService(new RepositoryFactory());

  • Chris Randle 67 posts 181 karma points c-trib
    Jun 18, 2015 @ 11:01
    Chris Randle
    6

    Just for reference in case anyone else is looking for the up-to-date reference (and being that I found this page from Googling umbraco memberservice) here the current (7.2+) version:

    var myMemberService = new MemberService(new RepositoryFactory(), new MemberGroupService(new RepositoryFactory()));
    var memberShipHelper = new MembershipHelper(UmbracoContext.Current);                    
    member = myMemberService.GetById(memberShipHelper.GetCurrentMemberId());
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 12, 2019 @ 20:45
    Alex Skrypnyk
    100

    Now it's even easier, in the surfaceController you can use just one line:

    var member = ApplicationContext.Current.Services.MemberService.GetById(Members.GetCurrentMemberId());
    

    If Members MembershipHElper isn't accessible:

    var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
    var member = ApplicationContext.Current.Services.MemberService.GetById(memberShipHelper.GetCurrentMemberId());
    
Please Sign in or register to post replies

Write your reply to:

Draft