ProfileBase.Properties 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會為設定檔中的每個屬性取得一組 SettingsProperty 物件。
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
屬性值
SettingsPropertyCollection SettingsProperty應用程式設定檔中每個屬性的物件。
例外狀況
無法建立 Web.config 檔案的 設定檔 區段中指定的屬性類型。
-或-
allowAnonymousWeb.config 檔案的設定檔區塊中屬性設定trueenabled為 ,匿名識別>元素的屬性<設false為 。
-或-
serializeAsWeb.config 檔案的剖析區段中屬性設定為 Binary ,且 的屬性為 ,且 typefalse的屬性為 IsSerializable 。
-或-
使用 provider 設定檔屬性指定的提供者名稱在集合中找不到 Providers 。
-或-
無法找到該剖面屬性的指定條件 type 。
-或-
設定檔屬性會以與設定檔區段屬性中基inherits底類別屬性名稱相符的名稱來指定。
範例
以下程式碼範例列出使用者設定檔中屬性的名稱,方法是將 Name 靜態 Properties 物件集合 SettingsProperty 的屬性綁定到控制 GridView 項。 選取的屬性值會依 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 資料。 A ProfileProvider 管理屬性值的儲存與取回資料來源與資料來源。