easy and simple way of implementing Sitecore User Profile Custom Properties.
Here we are storing Full Name in custom properties with the Property Name “Full Name”.
Go to Core database. We have to define a new template item and add all the property names that you want to store. We are storing Full Name.
Sitecore Path: /sitecore/templates/Users/Custom Profile
Here we have created a new folder Users and added a new template Custom Profile derived from Template. You can create a new template anywhere under the templates section.
2) Normally the user get stored with Profile – User: /sitecore/system/Settings/Security/Profiles/User
var user = Sitecore.Security.Accounts.User.Create("Consumer\" + "info@nikkipunjabi.com", "nikki"); user.Profile.ProfileItemId = "{6D01FC92-6B3A-4D17-84A9-FE1BD20E0D3E}"; user.Profile.SetCustomProperty("Full Name", "Nikki Punjabi"); user.Profile.Save(); user.Profile.Reload();
Note: Consumer – is the newly created Domain and Template ID: “{6D01FC92-6B3A-4D17-84A9-FE1BD20E0D3E}” is the ID of the new User Profile that we created! We have to pass the domain
and update the Profile ID of the user Otherwise we won’t be able to see the Custom Property Values in Sitecore. It is must to Save the Profile else value won’t be saved. Now this will create a new user and will have “Nikki Punjabi” as a value of Custom Property – “Full Name”.
Now let’s look at how to fetch Custom Property of a user.
bool loggedIn = Sitecore.Security.Authentication.AuthenticationManager.Login("Consumer\" + "info@nikkipunjabi.com", "nikki"); if (loggedIn) { string customPropertyValue = Sitecore.Context.User.Profile.GetCustomProperty("Full Name"); }
Demo
Application File: Download
If you know any other better approach or have any good idea then do give a shout by contacting me.
Reference:
https://briancaos.wordpress.com/2014/06/12/sitecore-users-custom-profile-properties/
Good Reads:
https://sdn.sitecore.net/upload/sitecore6/sc61keywords/security_api_cookbook_usletter.pdf
Happy Sitecoring!