ProfileBase.Properties Propriété

Définition

Obtient une collection d'objets SettingsProperty pour chaque propriété dans le profil.

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

Valeur de propriété

SettingsPropertyCollection

SettingsPropertyCollection d'objets SettingsProperty associée à chaque propriété dans le profil pour l'application.

Exceptions

Un type de propriété spécifié dans la section profile du fichier Web.config n’a pas pu être créé.

  • ou -

L’attribut allowAnonymous d’une propriété de la section profile du fichier Web.config est défini avec la valeur true, tandis que l’attribut enabled de l’élément <anonymousIdentification> est défini avec la valeur false.

  • ou -

L’attribut serializeAs d’une propriété de la section profile du fichier Web.config est défini avec la valeur Binary et la propriété IsSerializable du type spécifié retourne false.

  • ou -

Le nom d'un fournisseur spécifié à l'aide de l'attribut provider d'une propriété de profil est introuvable dans la collection Providers.

  • ou -

Impossible de trouver le type spécifié d'une propriété de profil.

  • ou -

Une propriété de profil a été spécifiée avec un nom qui correspond à un nom de propriété de la classe de base spécifiée dans l’attribut inherits de la section profile.

Exemples

L’exemple de code suivant répertorie les noms des propriétés dans le profil utilisateur en liant la Name propriété de la collection statique Properties d’objets SettingsProperty à un GridView contrôle. La valeur de propriété sélectionnée est récupérée par nom à l’aide de la Item[] collection. Pour obtenir un exemple d’un fichier Web.config qui spécifie les propriétés du profil utilisateur, consultez l’exemple fourni pour la ProfileBase classe.

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

Remarques

Vous pouvez utiliser cette propriété pour obtenir des informations sur les propriétés de profil configurées pour une application, y compris les noms et les types de propriétés. Vous pouvez également référencer chaque ProfileProvider propriété. Une gestion ProfileProvider du stockage et de la récupération des valeurs de propriété vers et depuis la source de données.

S’applique à

Voir aussi