Copied to clipboard

Flag this post as spam?

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

  • Andrew Waegel 126 posts 126 karma points
    Sep 07, 2011 @ 00:45
    Andrew Waegel

    Getting member ID from login name or username


    I'm having a problem that seems like it should be easy but it's not.

    Using the Umbraco API, I've just created a member. I want to use member ID as a foreign key in some tables for another app I've built. But I'm having a very difficult time getting this value; or more generally, the umbraco.cms.businesslogic.member.Member object.

    There are a bunch of deperecated methods like Member.GetMemberFromLoginName() that would probably work, but I don't want to used deprecated things. And I don't want to use login name in case that changes - numerical ID seems better.

    It's trivial to get this for the logged-in member via member.getcurrentmember(), but I can't find a way to do it for an arbitrary or not-yet-logged-on member.

    There's a good chance I'm missing something obvious here, so all suggestions are welcome.

    Using Umbraco 4.5.2 by the way - planning to upgrade soon.

  • Nigel Wilson 944 posts 2076 karma points
    Sep 07, 2011 @ 02:57
    Nigel Wilson

    Hi Andrew

    Would this work, or am I off track?

    Member m = Member.GetCurrentMember();
    int memberid = m.Id;


  • Andrew Waegel 126 posts 126 karma points
    Sep 07, 2011 @ 06:04
    Andrew Waegel

    Yep, it works just fine for the logged-in user; the problem is with another user where you know the login name but need the ID.

    In this case, it's in the 'create user' wizard - I'm making a custom registration page and I want to put the member id of the newly-created user into some other database tables that are part of a different app.

    - Andrew

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 07, 2011 @ 10:09
    Bo Damgaard Mortensen

    Hi Andrew,

    You can make a call to the GetMemberByLoginName() method:

    Member.GetMemberFromLoginName(string LoginName);

    - Bo

  • Dirk De Grave 4539 posts 6017 karma points MVP 3x admin c-trib
    Sep 07, 2011 @ 10:21
    Dirk De Grave



    which is more generic and uses the membership provider specified in web.config.




  • Andrew Waegel 126 posts 126 karma points
    Sep 07, 2011 @ 16:43
    Andrew Waegel

    Dirk, that's exactly it, thanks.

    Bo, Member.GetMemberByLoginName(username) works too, but VS tells me it's deprecated, so I was looking for a more durable solution.

    Thanks all,

    - Andrew

  • Jamie Maguire 2 posts 72 karma points
    Apr 23, 2018 @ 15:29
    Jamie Maguire

    Bit late in the day but for anyone else looking for this in 2018:

    var member = Membership.GetUser(model.Email);
    int memberId = (int) member.ProviderUserKey

    This will get you the nodeId of the recently created member

  • Robert J. Bullock 386 posts 405 karma points
    Aug 05, 2020 @ 14:05
    Robert J. Bullock

    That is so helpful! Thanks!

Please Sign in or register to post replies

Write your reply to: