Try as I might, I couldn't store new First and Last Name extended user data fields I added on the Create New Account page today.
The first and last name data is supposed to be serialized and stored as a key/value set in the PropertyNames and PropertyValues cs_userProfile fields. As you can see from the screenshot below, no extended user data is going in those fields-in-waiting.
[Information about user profile, the web.config and asp.net membership in original post removed... User Profile and User Extended Data are two different things. I needed both to integrate with another asp.net app which is why I brought them into the discussion. My bad. Sorry.]
User extended attributes are added to the CommunityServer.config file. Ours would look like this.
<ExtendedUserData>
<add name="FirstName" />
<add name="LastName" />
</ExtendedUserData>
They can then be added and managed in the CreateUserForm (sign-up), EditUserForm (profile edit), the UserAdd.aspx (CP Create User) and UserEdit.aspx (CP Edit User) pages. Interestingly, all of these were working correctly except when I created a new account with UserAdd.aspx.
The ExtendedAttributes GetSerializerData() method called in the SqlCommonDataProvider's CreateUpdateDeleteUser() method is looking for this.ExtendedAttributes and none were being passed from the UserAdd.aspx.cs.
public SerializerData GetSerializerData()
{
SerializerData data = new SerializerData();
string keys = null;
string values = null;
Serializer.ConvertFromNameValueCollection(this.extendedAttributes,ref keys, ref values);
data.Keys = keys;
data.Values = values;
return data; // DBVT - Always null since user object from UserAdd contains no extended attributes
}
The solution was to add the method used in other forms, SetExtendedUserData(user). This populates the attributes and allows us to store user extended data in the cs_userprofile property fields.
// Determine if the account was created successfully
switch (status)
{
// Everything went off fine, good
case CreateUserStatus.Created:
SaveAdditionalProfileData(user);
// DBVT Modified
SetExtendedUserData(user);
Response.Redirect(SiteUrls.Instance().ControlPanelUserAddedMessage(user.UserID));
break;
}
private void SetExtendedUserData(User user)
{
foreach (string controlName in ExtendedUserData.Fields)
{
Control c = TaskRegion.FindControl(controlName);
if (c != null)
{
string value = null;
if (c is TextBox)
value = ((TextBox)c).Text;
else if (c is ListControl)
value = ((ListControl)c).SelectedValue;
else if (c is CheckBox)
value = ((CheckBox)c).Checked.ToString();
if (value != null)
user.SetExtendedAttribute(c.ID, value);
}
}
Users.UpdateUser(user);
}
Isn't the Source Available application model a beautiful thing? That's all from the Community Server Adventure Channel today. Check back for our next exciting episode soon!
[UPDATE: This post was substantially updated 6/9 12:17 PM thanks to input from my friend José Lema. By the light of a new day, I should also add that I'm not suggesting that this is a Community Server bug, since the new user form isn't handling any extended attributes. But if you want to store user extended attributes in the UserAdd form, you'll need to add the SetExtendedUserData() method, which is the point of this post.]