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.

i hope you would use CreateUserWizard1.UserName for the user name as in:

ProfileBase p = ProfileBase.Create(CreateUserWizard1.UserName);

0

JT_SIROAuthor Commented: 2010-08-24

I got it working well now. Though, now I'm having trouble updating. I have an editable grid of all my users. My datasource has an update function called UpdateUser that takes a parameter of MembershipUtil, which is my custom membership class. The function saves to the MembershipUser object just fine, but it doesn't account for my Profile fields. I don't know how to pass the form values to my function, so I can update the Profile.

I tried adding parameters to my UpdateUser function, but it wouldn't allow it.

I can't explain this very well. But please let me know if you understand my problem and how to remedy it. Thanks- (my code is of my datasource object and the function in my custom class that performs the save. I commented out the updates that I tried to get to work, but failed.

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.

Thanks kris_per. That's exactly what I did, then I saw your post. It works!

It seems a little awkward to pack membership and profile fields into my MembershipUtil, but it accomplishes the front end experience I want. Is this normally broken into two Wizard steps or something? e.g., create username, password - then enter user info on another page that feeds the profile object?

Glad that you are getting it working....As you mention, Yes. What you think is right. I guess this page is to provide 'Manage Users' functionality (for admin). Typically in this page users list can be displayed in a grid with some basic columns like (name, email, islocked, isapproved) and last column with 'Edit User' link/button for each user row. When this button link is clicked, it will open another 'Edit User' page where you can display membership fields with 'Profile (Preferences)' fields in the same page (or in the next page). A final Update button will save the member and profile details...

Since Grid here is used only to display, it will not do the Update tasks...Also you can use the MembershipCollection type returned by Membership.GetAllUsers directly as Datasource for the Grid...this will avoid the usage of interim MembershipUtil class....Edit User page can get the values from fields and update the Membership details and profile details...so it is possible to avoid the usage of MembershipUtil class there as well...

0

JT_SIROAuthor Commented: 2010-08-25

Great, thanks for the help! One other question... I tried to deploy these pages to my Test environment on our production server and it's bombing on the profile properties when I put them in the web.config, as follows:
<profile>
<properties>
<add name="Nickname" defaultValue="default"/>
<add name="Initials" defaultValue="default"/>
<add name="PRO" defaultValue="default"/>
<add name="Phone" defaultValue="default"/>
</properties>
</profile>

I get this error:
This application was precompiled with personalization turned off, but it appears to have been turned on after the precompilation, which is not supported.