Copied to clipboard

Flag this post as spam?

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

  • Trent 15 posts 103 karma points
    Feb 19, 2016 @ 03:21

    Need to get logged in members ID weird issue

    For some reason I am not able to get a logged in users id.. here is my code:

                var membershipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
                // attempt to sign in using umbracos login method
                var signInSuccessful = membershipHelper.Login(user.Login, request.Password);
                if (signInSuccessful)
                  int userId = umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id;

    i get a null reference exception on the userId = it thinks there is no member.

    From what I can see everything should work, am i missing something in the config maybe?

    I would really appreciate any help.

    I have also tried: membershipHelper.GetCurrentMemberId();

    But this returns -1 :/

  • Kasper Holm 47 posts 180 karma points
    Feb 19, 2016 @ 06:21
    Kasper Holm

    Hello Trent

    Why dont you use the .GetByUsername(string username) ? since you've just logged him in ?

    If it has to be done else where, you could use the membershipHelper.GetCurrentMemberProfileModel() and then fetch the id by looking up the user from the user name ?

    Hope this helps :)

  • Trent 15 posts 103 karma points
    Feb 21, 2016 @ 21:06

    Nope, membershipHelper.GetCurrentMemberProfileModel() returns null. It's not working at all. There must be some setting in the web.config that isn't right.

Please Sign in or register to post replies

Write your reply to: