This documentation is archived and is not being maintained.

ProfileBase::SetPropertyValue Method

Sets the value of a profile property.

Namespace:  System.Web.Profile
Assembly:  System.Web (in System.Web.dll)

public:
void SetPropertyValue(
	String^ propertyName, 
	Object^ propertyValue
)

Parameters

propertyName
Type: System::String

The name of the property to set.

propertyValue
Type: System::Object

The value to assign to the property.

ExceptionCondition
System.Configuration.Provider::ProviderException

An attempt was made to set a property value on an anonymous profile where the property's allowAnonymous attribute is false.

System.Configuration::SettingsPropertyNotFoundException

There are no properties defined for the current profile.

-or-

The specified profile property name does not exist in the current profile.

-or-

The provider for the specified profile property did not recognize the specified property.

System.Configuration::SettingsPropertyIsReadOnlyException

An attempt was made to set a value value on a property that was marked as read-only.

System.Configuration::SettingsPropertyWrongTypeException

An attempt was made to assign a value to a property using an incompatible type.

ASP.NET uses the ProfileBase class to create the class used for the user profile. When an application that has the user profile enabled is started, ASP.NET creates a new class of type ProfileCommon, which inherits from the ProfileBase class. Strongly typed accessors are added to the ProfileCommon class for each property defined in the profile configuration section. The strongly typed accessors of the ProfileCommon class call the SetPropertyValue method to pass property values to the ProfileProvider to be stored at the data source.

You can use the SetPropertyValue method to assign property values in the user profile for your application by name. Values are untyped, and type checking will be done at run time, not compile time. For strongly typed access to profile property values, you can access the property by name as a member of the Profile property that is available on each page, for example, Profile.CustomerAddress.

The following code example shows an ASP.NET page that reads and sets the ZipCode property specified for the user profile. For an example of a Web.config file that specifies properties for the user profile, see the example provided for the ProfileBase class.

Security noteSecurity Note:

This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: