0

I am trying to update some custom profile properties programmatically via an ajax call. When the ajax fires, the property gets the new value, then I refresh the page and the new property is displayed. However it is not saved in the database [dbo.UserProfile]. If I clear the cache, then the old value re-appears.

Here is the code of my web method:

   Dim oProfileUserInfo As UserInfo = UserController.Instance.GetUserById(PortalSettings.PortalId, ProfileUserID)
   oProfileUserInfo.Profile.SetProfileProperty("myproperty", "new value")
   UserController.UpdateUser(PortalSettings.PortalId, oProfileUserInfo, True, False)

I'm using DNN 8.0.4

Any ideas?

alwaysVBNET
  • 3,150
  • 8
  • 32
  • 65

2 Answers2

0

The custom profile property Keys are case sensitive. So if you made a custom profile property with the name myproperty, then you should use it like this:

oProfileUserInfo.Profile.SetProfileProperty("myproperty", "new value")

Not like this:

oProfileUserInfo.Profile.SetProfileProperty("myProperty", "new value")

I assume you did create the custom property under "Admin > Site Settings > User Account Settings > Profile Settings".

Tested this on DNN 07.03.03, so maybe it works different in 8.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • yes, I'm using exactly the same letter case as the PropertyName from the ProfilePropertyDefinition table. It looks like the updates are temporarily stored in the cache, but don't know how to handle this. – alwaysVBNET Nov 03 '16 at 10:24
  • When I call `UserController.UpdateUser` the database is automatically updated. I also just tested the snippet in DNN 8. It works there also, the DNN 8 db is updated too. – VDWWD Nov 03 '16 at 10:41
  • maybe my table is corrupted? Are you aware of anything that might prevent those changes? – alwaysVBNET Nov 03 '16 at 10:45
  • Did you wrap it with a try-catch? Does the log show any errors? Do you have the right PortalId (users can be in more than 1 portal). You could try `Dim oProfileUserInfo As UserInfo UserController.GetUserByName(userName)`, see if that works. – VDWWD Nov 03 '16 at 11:32
  • Be sure to call the "update" user call after setting the profile, or it won't save (sorry, I see that was in the original post now) – Chris Hammond Nov 03 '16 at 14:00
0

I believe you need to use DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile().

Try:

Dim oProfileUserInfo As UserInfo = UserController.Instance.GetUserById(PortalSettings.PortalId, ProfileUserID)

oProfileUserInfo.Profile.SetProfileProperty("myproperty", "new value")

ProfileController.UpdateUserProfile(oProfileUserInfo)
Fix It Scotty
  • 2,852
  • 11
  • 12