Copied to clipboard

Flag this post as spam?

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


  • Hugo Migneron 32 posts 105 karma points
    Jul 10, 2015 @ 17:29
    Hugo Migneron
    0

    MemberService FindByUsername not working?

    Hi All,

    I'm trying to find a member on my website using the MemberService.

    When I use the following query :

    var umbracoMember = ApplicationContext.Current.Services.MemberService
                        .FindByUsername(username, 1, 10, out totalRecords, Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Exact)
                        .FirstOrDefault();
    

    umbracoMember ends up being null. However, in the same function if I use the old API to find the member :

    var oldApiMember = umbraco.cms.businesslogic.member.Member.GetMemberByName(username, true);
    

    oldApiMember is not null (and contains my member).

    When I look at the backend I see the member I am searching for :

    enter image description here

    Both the name and username are the same string, and I compared it to the "username" variable I use in my function, both are the same.

    What's going on? Why won't the service find it? My member belongs to the default member type "Member". I don't use Member Groups right now but added one just to test and made my member a part of it (it didn't change anything).

    Anyone has a clue where I should look?

    Thanks!

  • Hugo Migneron 32 posts 105 karma points
    Jul 10, 2015 @ 18:16
    Hugo Migneron
    0

    Kept digging around for this to work and trying with

    ApplicationContext.Current.Services.MemberService
                    .GetByUsername(username);
    

    actually works as expected. I'll go with that but i'm still very curious as to what's going on with the first code I posted (which seems like it should work). There must be a distinction I don't understand between the two methods?

    Thanks!

  • Hugo Migneron 32 posts 105 karma points
    Jul 29, 2015 @ 13:55
    Hugo Migneron
    0

    @AmandaEly : And what about if with the code I posted in my second post :

    ApplicationContext.Current.Services.MemberService
                    .GetByUsername(username);
    

    Does that work?

  • AmandaEly 123 posts 379 karma points
    Jul 29, 2015 @ 14:12
    AmandaEly
    0

    I have just been wrestling with this problem. In my case I had a leftover leading whitespace. Very hard to spot unless you copy and paste a good example and a bad example and compare.

  • KennethSiu 1 post 71 karma points
    May 19, 2016 @ 10:12
    KennethSiu
    0

    For anybody looking at this in the future, could it be that you're looking at index 1 instead of 0, so you're telling it to find the second page of results (which will be empty)? i.e. it should be:

    var umbracoMember = ApplicationContext.Current.Services.MemberService
                    .FindByUsername(username, 0, 10, out totalRecords, Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Exact)
                    .FirstOrDefault();
    
  • Calle Bjernekull 28 posts 103 karma points
    Jun 29, 2016 @ 09:21
    Calle Bjernekull
    0

    I'm running Umbraco 7.4.3 and can't get this to work. I'm using

    ApplicationContext.Current.Services.MemberService
                .GetByUsername(username);
    

    but always get result null. Anyone who wknows where to start looking?

  • Hannes 5 posts 75 karma points
    Sep 07, 2018 @ 07:33
    Hannes
    0

    I've had exactly this, working in 7.2.8.. Didn't touch the code, but in 7.12.1 it always returns null. Not sure what alternative to use?

    Could you get this to work? Or anyone else?

Please Sign in or register to post replies

Write your reply to:

Draft