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();
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.
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
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!
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!
Thanks for the suggestions, I'll post again if I run into further problems.
is working on a reply...