0

I have created a class to handle membership user creation with custom fields.

I have done it based on this solutions:

And now I'm trying to use create the user and get the profile data:

if (Membership.GetUserNameByEmail(email) == null)
{
MembershipUser member = Membership.CreateUser(username, password, email);

Roles.AddUserToRole(username, "WebsiteUsers");

CCL.MemberProfile currentProfile = CCL.MemberProfile.CurrentUser;

bool exists = currentProfile != null;
Response.Write(exists.ToString());
}

but currentProfile is returning null.

So I'm unable to assign values from the form to my member custom properties which are handled by the properties set in the class :(

I don't get how I can make it working :(

Does anyone have some thoughts? Thanks

Community
  • 1
  • 1
nickornotto
  • 1,946
  • 4
  • 36
  • 68

1 Answers1

1

Suggestion 1:

Make sure that ProfileBase.Create returns something that can be cast to a "MemberProfile", otherwise if it can't then casting it will just return NULL.

Suggestion 2:

Make sure the context you are running in has a logged in user, so your call to Membership.GetUser() can find the current user object.

Other thoughts:

The ProfileBase.Create method assumes that the username you pass in is an authenticated user, I'm not sure on it's behavior when the user isn't authenticated..maybe it returns NULL?

g7876413
  • 279
  • 2
  • 9
  • Thanks @g7876413, I validated the user so it returns currentProfile correctly. However when I try to assign my custom values: `currentProfile.FullName = "Lucy"; currentProfile.Save();` it doesn't work :( Any suggestions? – nickornotto Mar 26 '13 at 14:24
  • Sorry @user1611620, the only other thing I can suggest is checking your implementation of the "MemberProfile" class, in the example you referenced the set method on the "Fullname" property seemed to be calling Save() as well as setting the value, so you shouldn't need to call it after setting the value yourself. Also check you haven't re-implemented Save() and made it do anything different to the base.Save(). – g7876413 Mar 26 '13 at 15:58
  • 1. I had custom properties defined in my web.config but they were causing error 'property already defined' so I removed the section - after I put it back it started to work. I changed the names of the properties (in member type in umbraco & in web.config) as the same name given in my class were causing the above error. 2. I changed my script to update member profile AFTER authentication-this required reloading the page. Adding member to role wasn't working as well before the user was authenticated/ page reloaded. TO SUMMARISE: thanks @g7876413 for advice as it led me to the right direction – nickornotto Mar 27 '13 at 16:57
  • No problem @user1611620 glad to be at least a little help, thanks for posting the solution too :) – g7876413 Mar 27 '13 at 18:19