Copied to clipboard

Flag this post as spam?

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


  • Ryan 34 posts 138 karma points
    Apr 07, 2015 @ 12:33
    Ryan
    0

    Updating Member Programmatically

    Hi all,

    I'm trying to update membership details through an API controller, the "Create" method was simple enough but I'm slightly confused as to why my "Update" method isn't working, specifically

    helper.GetCurrentMemberProfileModel();
    

    The function in question is always returning null even when I've successfully logged in prior. If anyone could point out where I'm going wrong that would be great!

    var helper = new MembershipHelper(UmbracoContext.Current);
    helper.Login("myusername", "mypassword");
    
    //Always returns null
    var profile = helper.GetCurrentMemberProfileModel();
    
  • Cristhian Amaya 52 posts 423 karma points
    Apr 07, 2015 @ 14:35
    Cristhian Amaya
    0

    Hi Ryan,

    The problem is on the Login method but I'm not sure why it is failing. If you do the authentication manually, which is basically FormsAuthentication.SetAuthCookie("username", true), the GetCurrentMemberProfileModel will work as expected.

    Also, please note that you must authenticate the user on a different request before you can get the user data with the that method, that's because that method relies on the User.Identity.IsAuthenticated property and that property is not set if there are no auth cookie.

    So, in summary, you should authenticate the user in one request (manually or find why the login method is failing) and update it in another request.

    Another option to get members info is using the member service https://our.umbraco.org/documentation/Reference/Management-v6/Services/MemberService which I think is better on newer Umbraco versions.

    Hope this helps. Cheers!

  • Ryan 34 posts 138 karma points
    Apr 07, 2015 @ 15:25
    Ryan
    0

    Thanks for the suggestions, I'll post again if I run into further problems.

Please Sign in or register to post replies

Write your reply to:

Draft