ProfileBase.Properties 属性

定义

获取配置文件中每个属性的 SettingsProperty 对象的集合。

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

应用程序配置文件中每个属性的 SettingsPropertyCollection 对象的 SettingsProperty 集合。

例外

未能创建在 Web.config 文件的配置文件节中指定的属性类型。

  • 或 -

将 Web.config 文件的配置文件节中某个属性的 allowAnonymous 特性设置为 true,并将 <anonymousIdentification> 元素的 enabled 特性设置为 false

  • 或 -

将 Web.config 文件配置文件节中某个属性的 serializeAs 特性设置为 Binary,指定的 typeIsSerializable 属性将返回 false

  • 或 -

未能在 Providers 集合中找到使用配置文件属性的 provider 特性指定的提供程序名称。

  • 或 -

未能找到为配置文件属性指定的 type

  • 或 -

使用与基类中的属性名称匹配的名称指定配置文件属性,基类在配置文件节的 inherits 特性中指定。

示例

下面的代码示例通过将对象的静态Properties集合SettingsPropertyGridView中的属性绑定到Name控件列出用户配置文件中属性的名称。 使用集合按名称 Item[] 检索所选属性值。 有关指定用户配置文件属性的Web.config文件的示例,请参阅为 ProfileBase 类提供的示例。

<%@ 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>

注解

可以使用此属性获取有关为应用程序配置的配置文件属性的信息,包括属性名称和类型。 还可以引用 ProfileProvider 每个属性。 管理 ProfileProvider 对数据源和数据源属性值的存储和检索。

适用于

另请参阅