Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Sitecore: persisting user data

Modified: 2013/04/02 15:36 by vanthoog - Categorized as: Sitecore
Sitecore contains a mechanism for storing user specific data. This mechanism is implemented by the class Sitecore.Web.UI.HtmlControls.Registry. It contains the following methods for storing user specific data:

	SetBool(string key, bool val)
	SetInt(string key, int val)
	SetString(string key, string value)
	SetValue(string key, string value)

Note: The methods SetString and SetValue are identical.

And it contains the following methods for retrieving user specific data:

	GetBool(string key) and GetBool(string key, bool defaultvalue)
	GetInt(string key) and GetInt(string key, int defaultvalue)
	GetString(string key) and GetString(string key, string defaultvalue)
	GetValue(string key)

Note: The method GetValue does not have an overload with two parameters. Furthermore, the methods GetValue and GetString are identical.

When using the set methods the combination of key and value is stored in the core database in the field ProPertyValuesBinary of the table aspnet_Profile. This means that this data is still available after a restart of the website.

Here is an example. Suppose in your custom code you have a form containing a textbox for entering an emailaddress. You can use the method SetString to persist the entered emailaddress:

	Sitecore.Web.UI.HtmlControls.Registry.SetString("emailaddress", EmailTextBox.Text);

And you can use the method GetString to preload the emailaddress when the user views the form again:

	EmailTextBox.Text = Sitecore.Web.UI.HtmlControls.Registry.GetString("emailaddress");

 © Evident Interactive BV