Update an existing user's profile in ASP.NET

Or Betzalel picture Or Betzalel · Sep 19, 2009 · Viewed 8.9k times · Source

I want to change an existing user's profile without having to create a new profile for the user. For example: I have a user name Usr1 and I want to change only his age, how do I do that?

Answer

Ravinder Singh picture Ravinder Singh · Nov 4, 2009

When you are in the page you have the ProfileCommon class available to you for accessing the profile. The profilecommon class is automatically generated by asp.net from you web.config profile settings during compilation of the web project.

In case you want to use the profile from app_code folder, you will have to use the profilebase class. Profilecommon that is available in the page also derives from this class.

Profilebase can be access like this

HttpContext.Profile or HttpContext.Current.Profile

To read a profile value you need to do the following

HttpContext.Profile.GetPropertyValue("propertyName");

To write a value to the profile you need to write

HttpContext.Profile.SetPropertyValue("propertyName", "propertyValue");