ProfileBase.Properties Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar en samling SettingsProperty objekt för varje egenskap i profilen.
public:
static property System::Configuration::SettingsPropertyCollection ^ Properties { System::Configuration::SettingsPropertyCollection ^ get(); };
public static System.Configuration.SettingsPropertyCollection Properties { get; }
static member Properties : System.Configuration.SettingsPropertyCollection
Public Shared ReadOnly Property Properties As SettingsPropertyCollection
Egenskapsvärde
En SettingsPropertyCollection av SettingsProperty objekten för varje egenskap i programmets profil.
Undantag
Det gick inte att skapa en egenskapstyp som anges i profilavsnittet i Web.config-filen.
-eller-
Attributet allowAnonymous för en egenskap i profilavsnittet i Web.config-filen är inställt på true och enabledattributet för elementet< anonymousIdentification> är inställt på false.
-eller-
Attributet serializeAs för en egenskap i profilavsnittet i Web.config-filen är inställt på Binary och IsSerializable egenskapen för den angivna type returnerar false.
-eller-
Det gick inte att hitta namnet på en provider som angetts med provider attributet för en profilegenskap i Providers samlingen.
-eller-
Det gick inte att hitta den type angivna för en profilegenskap.
-eller-
En profilegenskap har angetts med ett namn som matchar ett egenskapsnamn för den basklass som anges i attributet för inheritsprofilavsnittet .
Exempel
I följande kodexempel visas namnen på egenskaperna i användarprofilen genom att binda Name egenskapen från den statiska Properties samlingen av SettingsProperty objekt till en GridView kontroll. Det valda egenskapsvärdet hämtas med namnet med hjälp av Item[] samlingen. Ett exempel på en Web.config fil som anger egenskaper för användarprofilen finns i exemplet för ProfileBase klassen.
<%@ 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>
Kommentarer
Du kan använda den här egenskapen för att få information om profilegenskaperna som konfigurerats för ett program, inklusive egenskapsnamn och typer. Du kan också referera till ProfileProvider varje egenskap. En ProfileProvider hanterar lagring och hämtning av egenskapsvärden till och från datakällan.