Question

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?

Was it helpful?

Solution

See this article for the full details. Be aware that in certain cases (see my comment to another answer), ProfileCommon is not generated.

In this case you need to revert to using ProfileBase:

ProfileBase profile = context.Profile;
DateTime dob= profile.GetPropertyValue("dob") as DateTime;
...
profile.SetPropertyValue("dob",dob);

OTHER TIPS

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");

If what you are trying to do is update another's user profile (say, you are an admin who types in a customer's username), you can use something like the following.

Dim p As ProfileCommon = Profile.GetProfile("Usr1")

p.TestValue1 = "New Value"
p.TestValue2 = "Another New Value"

p.Save()

Again, if you are using a web project instead of a web site, you will have to use p.SetPropertyValue() instead of the strong-typed property names.

I have a similar problem and search for solution with sql script. It is little bit more difficult but it is doable in case server side code is not an option. I set two fields in dbo.aspnet_Profile (PropertyValuesString, PropertyNames)

UPDATE dbo.aspnet_Profile 
SET 
PropertyValuesString = cast(Replace(cast(PropertyValuesString as nvarchar(max)),'New Value','Old Value') as ntext)
,PropertyNames='New calculated property names'
WHERE 
UserId='userID'

Difficult part is to change PropertyNames field.It contains profile name property, start position, and length. Something like that : address:S:31:12 You have to recalculated start positions and lengths accordingly new value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top