ProfileBase.Properties Propiedad

Definición

Obtiene una colección de objetos SettingsProperty para cada propiedad del perfil.

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

Valor de propiedad

SettingsPropertyCollection

Colección SettingsPropertyCollection de objetos SettingsProperty para cada propiedad del perfil para la aplicación.

Excepciones

No se pudo crear un tipo de propiedad especificado en la sección profile del archivo Web.config.

o bien

El valor del atributo allowAnonymous de una propiedad en la sección profile del archivo Web.config está establecido en true y el atributo enabled del elemento <anonymousIdentification> está establecido en false.

o bien

El valor del atributo serializeAs de una propiedad en la sección profile del archivo Web.config está establecido en Binary y la propiedad IsSerializable del valor type especificado devuelve false.

o bien

El nombre de un proveedor especificado utilizando el atributo provider de una propiedad de perfil no se pudo encontrar en la colección Providers.

o bien

No se pudo encontrar el type especificado para una propiedad de perfil.

o bien

Se especificó una propiedad de perfil con un nombre que coincide con un nombre de propiedad en la clase base especificada en el atributo inherits de la sección profile.

Ejemplos

En el ejemplo de código siguiente se enumeran los nombres de las propiedades del perfil de usuario enlazando la Name propiedad de la colección estática Properties de SettingsProperty objetos a un GridView control . El valor de propiedad seleccionado se recupera por nombre mediante la Item[] colección . Para obtener un ejemplo de un archivo de Web.config que especifica las propiedades del perfil de usuario, vea el ejemplo proporcionado para la ProfileBase clase .

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

Comentarios

Puede usar esta propiedad para obtener información sobre las propiedades de perfil configuradas para una aplicación, incluidos los nombres de propiedad y los tipos. También puede hacer referencia a la ProfileProvider propiedad de cada propiedad. Administra ProfileProvider el almacenamiento y la recuperación de valores de propiedad hacia y desde el origen de datos.

Se aplica a

Consulte también