I have 2 Portals in my dnn installation... each Portal has a set of custom ProfileProperties defined, each with a unique Category name. ("PPA" and "PPB" - the actual ProfileProperties within each category have the same names: pp1, pp2, etc...)
My login script is all customized, and I have no problem creating and populating these ProfileProperties for a new user the first time they login to one of the 2 portals. If, however, a user from Portal A attempts to login to Portal B, I cannot get the custom ProfileProperties to be created for Portal B.
At first, the values for the PPA properties were being updated when logging into Portal B... I've solved that issue, but now I cannot get the PPB properties to be created at all... What am I doing wrong here?
//Get all of the Company specific Profile Properties
ProfilePropertyDefinitionCollection ppdc = UserInfo.Profile.ProfileProperties.GetByCategory(strProfileCategory);
ProfilePropertyDefinitionCollection myProps = ProfileController.GetPropertyDefinitionsByCategory(PortalId, strProfileCategory);
sb.Append("<tr><td>Property Count: " + ppdc.Count.ToString() + " | " + myProps.Count.ToString() + "</td></tr>");
ProfileController.UpdateUserProfile(objUserInfo, myProps);
if (ppdc.Count != myProps.Count)
{
sb.Append("<tr><td>Creating Profile Properties for " + strProfileCategory + "...</td></tr>");
UserInfo.Profile.ProfileProperties.AddRange(myProps);
ppdc = UserInfo.Profile.ProfileProperties.GetByCategory(strProfileCategory);
sb.Append("<tr><td>Profile Properties Created! - " + ppdc.Count.ToString() + "</td></tr>");
}
sb.Append("<tr><td><ul>");
for (int i = 0; i < ppdc.Count; i++)
{
string strName = ppdc[i].PropertyName;
int intID = ppdc[i].PropertyDefinitionId;
ProfilePropertyDefinition ppd2 = objUserInfo.Profile.ProfileProperties.GetById(intID);//.GetByName(strName);
if (ppd2 == null)
{
ProfilePropertyDefinition userPPD = ProfileController.GetPropertyDefinition(intID);
UserInfo.Profile.ProfileProperties.Add(userPPD);
ProfileController.UpdateUserProfile(objUserInfo, objUserInfo.Profile.ProfileProperties);
ppd2 = objUserInfo.Profile.ProfileProperties.GetById(intID);
}
if (ppd2 != null)
{
sb.Append("<li>" + strName + ": " + ppd2.PropertyValue + " | " + ppd2.PropertyDefinitionId.ToString());
switch (strName)
{
case "pp1":
ppd2.PropertyValue = myValue;
break;
default:
ppd2.PropertyValue = ppd2.DefaultValue;
break;
}
sb.Append("<ul><li>New Value: " + ppd2.PropertyValue + "</li></ul>");
UserInfo.Profile.SetProfileProperty(strName, ppd2.PropertyValue);
ProfileController.UpdateUserProfile(objUserInfo, objUserInfo.Profile.ProfileProperties);
sb.Append("</li>");
}
else
{
sb.Append("<li>Property ID Not Found: " + strName + " | " + intID.ToString() + "</li>"); (This error line is returned)
}
}
My logging returns the following:
Updating Profile for Portal B... |
Property Count: 0 | 6 |
Creating Profile Properties for Portal B... |
Profile Properties Created! - 6 |
- Property ID Not Found: pp1 | 84
- Property ID Not Found: pp2 | 85
- Property ID Not Found: pp3 | 86
- Property ID Not Found: pp4 | 87
- Property ID Not Found: pp5 | 91
- Property ID Not Found: pp6 | 88
|
The UserProfile table has links to the Profile and ProfilePropertyDefinition for PortalA, but it does not contain the required links for PortalB...
It seems to me that the code is correctly looking for the ProfileProperties for the correct Portal and Category name, it is finding that these properties do not exist, it attempts to create them (and thinks that it does), and then attempts to set the values for the ProfileProperties, but ppd2 is returning null since the ProfileProperties were never created in the previous step. So I believe the red lines above are my issue, but I don't understand why that would seem to work for completely new users in either Portal but not work for existing Users when attempting to login to the Portal in which they were not initially created.
I feel like there is some redundant code up there, but I've just been trying to add commands to force the creation of these Properties... I'm sure there is some stuff I need to remove. Any help, as always, is appreciated; thanks!