Question : ASP.NET Membership and Profile Set Up

I'm setting up a membership creation page for my .NET app.  I'm able to create a basic user just fine, but want to add a few custom fields to the users profile.  How do I populate profile values for another user?  See code below - I create a MembershipUser object from a CreateUserWizard. BUT I need to add a few profile value right after I create the user.  I can't seem to find the syntax.  Basically, I want to:

Update the "PhoneNumber" profile field for the user usr, that I just created.  I've created the PhoneNumber property in web.config already.

If I use Profile.PhoneNumber, that will apply to Me, as the logged in user.  I don't want that.  I want it to be applied to the profile of the user I am creating.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
if (Membership.GetUser() != null)
			{
				MembershipUser usr = Membership.GetUser(CreateUserWizard1.UserName);
				usr.UnlockUser();
				usr.IsApproved = true;
                
				Membership.UpdateUser(usr);
               
                // Update profile info - how???


				CreateUserWizard1.ContinueDestinationPageUrl = "~/Admin_Pages/Administrator/UserAdministration.aspx";
			}
			else
			{
				CreateUserWizard1.ContinueDestinationPageUrl = "~/Admin_Pages/Administrator/UserAdministration.aspx";
			}

Answer : ASP.NET Membership and Profile Set Up

I think I understand the issue. See if the below would fit.

If you want to (or currently) display the Profile fields also in the grid along with the membershipuser fields, then:      

- you can add profile fields as property members to MembershipUtil class and      

- update Grid to show profile fields as well. This will take care of loading/updating MembershipUtil object with both user and profile fields.      

- In GetMembershipUtil method, get profile details also from store and transfer them to MembershipUtil object properties.      
      To load profile from store, Create method itselft can be used like:
      ProfileBase p = ProfileBase.Create(MembershipUtil.Username);
      // use p.GetPropertyValue method to read values from profile object and then transfer them to MembershipUtil object.

- In UpdateUser method, when updating for user details, Save profile details also      
      To save profile:
      ProfileBase p = ProfileBase.Create(MembershipUtil.Username);
      // use p.SetPropertyValue method to set values in profile object
      p.Save();

Make sure all the profile properties are added in web.config as well.      
Random Solutions  
 
programming4us programming4us