ProfileBase.Properties Property
Gets a collection of SettingsProperty objects for each property in the profile.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.Configuration.SettingsPropertyCollectionA SettingsPropertyCollection of SettingsProperty objects for each property in the profile for the application.
| Exception | Condition |
|---|---|
| System.Configuration.ConfigurationErrorsException | A property type specified in the section of the Web.config file could not be created. -or- The allowAnonymous attribute for a property in the section of the Web.config file is set to true and the enabled attribute of the element is set to false. -or- The serializeAs attribute for a property in the section of the Web.config file is set to Binary and the IsSerializable property of the specified type returns false. -or- The name of a provider specified using the provider attribute of a profile property could not be found in the Providers collection. -or- The type specified for a profile property could not be found. -or- A profile property was specified with a name that matches a property name on the base class specified in the inherits attribute of the section. |
You can use this property to get information about the profile properties configured for an application, including property names and types. You can also reference the ProfileProvider of each property. A ProfileProvider manages storage and retrieval of property values to and from the data source.
The following code example lists the names of the properties in the user profile by binding the Name property from the static Properties collection of SettingsProperty objects to a GridView control. The selected property value is retrieved by name using the Item collection. For an example of a Web.config file that specifies properties for the user profile, see the example provided for the ProfileBase class.
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Profile" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Public Sub Page_Load() If Not IsPostBack Then PropertiesListBox.DataSource = ProfileBase.Properties PropertiesListBox.DataBind() End If If Not PropertiesListBox.SelectedItem Is Nothing Then Dim propValue As Object = Profile(PropertiesListBox.SelectedItem.Text) Dim propType As Type = propValue.GetType() ' If the property is a value type, return ToString(). If propType Is GetType(String) Or propType.IsValueType Then ValueLabel.Visible = True ValueGridView.Visible = False ValueLabel.Text = propValue.ToString() Return End If ' Bind the property to a GridView. Try ValueGridView.DataSource = propValue ValueGridView.DataBind() ValueGridView.Visible = True ValueLabel.Visible = False Catch ' If the property is not bindable, return ToString(). ValueLabel.Visible = True ValueGridView.Visible = False ValueLabel.Text = propValue.ToString() End Try End If End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Home Page</title> </head> <body> <h3>View Profile properties:</h3> <form id="form1" runat="server"> <table border="0" cellpadding="2" cellspacing="2"> <tr> <td>Property</td> <td>Value</td> </tr> <tr> <td valign="top"> <asp:ListBox runat="server" id="PropertiesListBox" Rows="10" AutoPostBack="True" DataTextField="Name" /> </td> <td valign="top"> <asp:GridView runat="Server" id="ValueGridView" Visible="False" /> <asp:Label runat="Server" id="ValueLabel" Visible="False" /> </td> </tr> </table> </form> </body> </html>
Available since 2.0