ProfileBase.Properties Proprietà

Definizione

Ottiene un insieme di oggetti SettingsProperty per ciascuna proprietà del profilo.

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

Valore della proprietà

SettingsPropertyCollection

Un insieme SettingsPropertyCollection di oggetti SettingsProperty per ciascuna proprietà del profilo dell'applicazione.

Eccezioni

Non è stato possibile creare un tipo di proprietà specificato nella sezione profile del file Web.config.

-oppure-

L'attributo allowAnonymous di una proprietà nella sezione profile del file Web.config è impostato su true e l'attributo enabled dell'elemento <anonymousIdentification> è impostato su false.

-oppure-

L'attributo serializeAs di una proprietà nella sezione profile del file Web.config è impostato su Binary e la proprietà IsSerializable di type specificato restituisce false.

-oppure-

Non è stato possibile trovare il nome di un provider specificato mediante l'attributo provider di una proprietà del profilo nell'insieme Providers.

-oppure-

Non è stato possibile trovare il type specificato per una proprietà del profilo.

-oppure-

Una proprietà del profilo è stata specificata con un nome corrispondente a una proprietà nella classe base specificata nell'attributo inherits della sezione profile.

Esempio

Nell'esempio di codice seguente vengono elencati i nomi delle proprietà nel profilo utente associando la Name proprietà dall'insieme statico Properties di SettingsProperty oggetti a un GridView controllo . Il valore della proprietà selezionato viene recuperato in base al nome utilizzando la Item[] raccolta. Per un esempio di file Web.config che specifica le proprietà per il profilo utente, vedere l'esempio fornito per 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>

Commenti

È possibile utilizzare questa proprietà per ottenere informazioni sulle proprietà del profilo configurate per un'applicazione, inclusi i nomi e i tipi di proprietà. È anche possibile fare riferimento all'oggetto ProfileProvider di ogni proprietà. Un ProfileProvider oggetto gestisce l'archiviazione e il recupero dei valori delle proprietà da e verso l'origine dati.

Si applica a

Vedi anche