Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Apr 08, 2021 @ 09:42
    Simon Dingley
    0

    MemberService.GetAllRoles Returns No Results for Members

    Are there any known issues with the GetAllRoles method in v7? I am getting no results using member id or login name yet if I use System.Web.Security.Roles.GetRolesForUser(loginName) I do get results albeit the wrong results.

    Using the System.Web.Security.Roles.GetRolesForUser method I am not getting accurate results where I am calling it in my MemberIndexerGatheringNodeData event handler. If I change the member groups in Umbraco and save the member I do not get back the new groups only the previous groups until the member is saved for a second time. This leads to inaccurate data being stored in the examine index for members.

    If there are known issues any suggestions to work around this without having to rely on editors to save members twice would be helpful.

    Thanks

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Oct 20, 2021 @ 15:48
    Simon Dingley
    101

    Until a few moments ago I was still fighting with this issue but thanks to this post which led me to a workaround for the problem I finally have something working! Quite obvious now looking at it.

    private void MemberService_Saved(IMemberService sender, global::Umbraco.Core.Events.SaveEventArgs<IMember> e)
    {
        foreach (var member in e.SavedEntities)
        {
            // Reindex node after a delay to work around the fact that roles have not 
            // been updated by the time the MemberService.Saved event executes
            System.Threading.Tasks.Task.Run(() => 
            {
                System.Threading.Thread.Sleep(5000);
                ExamineManager.Instance.ReIndexNode(member.ToXml(), IndexTypes.Member);
            });     
        }
    }
    
  • Janus Kamp Hansen 16 posts 153 karma points
    Oct 20, 2021 @ 16:02
    Janus Kamp Hansen
    0

    Mission accomplished! If I was able to at least help one - it was worth the effort 😉. Glad it helped and thank you for your reply. 🤟#h5yr2

Please Sign in or register to post replies

Write your reply to:

Draft