ProfileBase.Properties 属性
定义
获取配置文件中每个属性的 SettingsProperty 对象的集合。Gets a collection of SettingsProperty objects for each property in the profile.
public:
static property System::Configuration::SettingsPropertyCollection ^ Properties { System::Configuration::SettingsPropertyCollection ^ get(); };
public static System.Configuration.SettingsPropertyCollection Properties { get; }
member this.Properties : System.Configuration.SettingsPropertyCollection
Public Shared ReadOnly Property Properties As SettingsPropertyCollection
属性值
应用程序配置文件中每个属性的 SettingsPropertyCollection 对象的 SettingsProperty 集合。A SettingsPropertyCollection of SettingsProperty objects for each property in the profile for the application.
例外
未能创建在 Web.config 文件的配置文件节中指定的属性类型。A property type specified in the profile section of the Web.config file could not be created.
- 或 --or-
将 Web.config 文件的配置文件节中某个属性的 allowAnonymous 特性设置为 true,并将 <anonymousIdentification> 元素的 enabled 特性设置为 false。The allowAnonymous attribute for a property in the profile section of the Web.config file is set to true and the enabled attribute of the <anonymousIdentification> element is set to false.
- 或 --or-
将 Web.config 文件配置文件节中某个属性的 serializeAs 特性设置为 Binary,指定的 type 的 IsSerializable 属性将返回 false。The serializeAs attribute for a property in the profile section of the Web.config file is set to Binary and the IsSerializable property of the specified type returns false.
- 或 --or-
未能在 Providers 集合中找到使用配置文件属性的 provider 特性指定的提供程序名称。The name of a provider specified using the provider attribute of a profile property could not be found in the Providers collection.
- 或 --or-
未能找到为配置文件属性指定的 type。The type specified for a profile property could not be found.
- 或 --or-
使用与基类中的属性名称匹配的名称指定配置文件属性,基类在配置文件节的 inherits 特性中指定。A profile property was specified with a name that matches a property name on the base class specified in the inherits attribute of the profile section.
示例
下面的代码示例通过 Name 将属性从静态 Properties 对象集合绑定 SettingsProperty 到控件来列出用户配置文件中的属性的名称 GridView 。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. 选定的属性值使用集合按名称检索 Item[] 。The selected property value is retrieved by name using the Item[] collection. 有关指定用户配置文件属性的 Web.config 文件的示例,请参阅为类提供的示例 ProfileBase 。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="C#" %>
<%@ 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 void Page_Load()
{
if (!IsPostBack)
{
PropertiesListBox.DataSource = ProfileBase.Properties;
PropertiesListBox.DataBind();
}
if (PropertiesListBox.SelectedItem != null)
{
object propValue = Profile[PropertiesListBox.SelectedItem.Text];
Type propType = propValue.GetType();
// If the property is a value type, return ToString().
if (propType == typeof(string) || propType.IsValueType)
{
ValueLabel.Visible = true;
ValueGridView.Visible = false;
ValueLabel.Text = propValue.ToString();
return;
}
// 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();
}
}
}
</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>
<%@ 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>
注解
您可以使用此属性来获取有关为应用程序配置的配置文件属性的信息,包括属性名称和类型。You can use this property to get information about the profile properties configured for an application, including property names and types. 您还可以引用 ProfileProvider 每个属性的。You can also reference the ProfileProvider of each property. ProfileProvider管理与数据源之间的属性值的存储和检索。A ProfileProvider manages storage and retrieval of property values to and from the data source.