ProfileGroupBase 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供無類型存取群組 ASP.NET 屬性價值。
public ref class ProfileGroupBase
public class ProfileGroupBase
type ProfileGroupBase = class
Public Class ProfileGroupBase
- 繼承
-
ProfileGroupBase
範例
以下 Web.config 檔案指定一個使用者設定檔,包含一組屬性,群組名稱為 Address。 為電流HttpContext性質所產生Profile的分組性質前會加上群名,例如。 Profile.Address.Street 第二個範例顯示一個 ASP.NET 頁面,用來儲存並檢索已設定的設定檔屬性。
<configuration>
<connectionStrings>
<add name="SqlServices" connectionString=
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
</connectionStrings>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx"
name=".ASPXFORMSAUTH" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<membership defaultProvider="SqlProvider"
userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SqlServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
passwordFormat="Hashed"
applicationName="MyApplication" />
</providers>
</membership>
<profile enabled="true" defaultProvider="SqlProvider">
<providers>
<add
name="SqlProvider"
connectionStringName="SqlServices"
applicationName="MyApplication"
type="System.Web.Profile.SqlProfileProvider" />
</providers>
<properties>
<add name="ZipCode" />
<group name="Address">
<add name="Street" />
<add name="City" />
<add name="State" />
<add name="CountryOrRegion" />
</group>
</properties>
</profile>
</system.web>
</configuration>
以下程式碼範例展示了一個 ASP.NET 頁面,讀取並設定為使用者設定檔指定的群組屬性。
這很重要
此範例包含一個接受使用者輸入的文字框,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述。
<%@ Page Language="C#" %>
<!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)
{
StreetTextBox.Text = Profile.Address.Street;
CityTextBox.Text = Profile.Address.City;
StateTextBox.Text = Profile.Address.State;
CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion;
ZipCodeTextBox.Text = Profile.ZipCode;
}
}
public void UpdateButton_OnClick(object sender, EventArgs args)
{
Profile.Address.Street = StreetTextBox.Text;
Profile.Address.City = CityTextBox.Text;
Profile.Address.State = StateTextBox.Text;
Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text;
Profile.ZipCode = ZipCodeTextBox.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>Street Address</td>
<td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
</tr>
<tr>
<td>City</td>
<td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>State</td>
<td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>Zip Code</td>
<td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
</tr>
<tr>
<td>Country</td>
<td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
</tr>
</table>
<asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!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
StreetTextBox.Text = Profile.Address.Street
CityTextBox.Text = Profile.Address.City
StateTextBox.Text = Profile.Address.State
CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion
ZipCodeTextBox.Text = Profile.ZipCode
End If
End Sub
Public Sub UpdateButton_OnClick(sender As Object, args As EventArgs)
Profile.Address.Street = StreetTextBox.Text
Profile.Address.City = CityTextBox.Text
Profile.Address.State = StateTextBox.Text
Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text
Profile.ZipCode = ZipCodeTextBox.Text
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>Street Address</td>
<td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
</tr>
<tr>
<td>City</td>
<td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>State</td>
<td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>Zip Code</td>
<td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
</tr>
<tr>
<td>Country</td>
<td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
</tr>
</table>
<asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />
</form>
</body>
</html>
備註
ASP.NET 使用 該ProfileGroupBase類別在屬性中建立當前 HttpContext的群組屬性Profile。 當屬性被指定為一組屬性時,使用 profile 的 group Element(ASP.NET Settings Schema)的屬性,ASP.NET 會為群組中的每個屬性建立一個新的類別,並對每個屬性建立強型別的存取器。 新類別繼承基礎 ProfileGroupBase 類別。 新類別的強型別存取器呼叫GetPropertyValue基ProfileGroupBase底類別的 and SetPropertyValue 方法,分別取回並設定 profile 屬性值。
傳遞ProfileGroupBase呼叫時,會取得並設定屬性值給繼承ProfileBase該類別的方法所提供的InitProfileGroupBase類別。 請參閱該 ProfileBase 類別以獲得更多關於行為、例外等的資訊。
這個類別並非用來從你的程式碼中建立的。
建構函式
| 名稱 | Description |
|---|---|
| ProfileGroupBase() |
建立 ProfileGroupBase 類別的執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Item[String] |
取得或設定一個以物業名稱為索引的分組房產價值。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetPropertyValue(String) |
取得群組型房的價值。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| Init(ProfileBase, String) |
ASP.NET 用於初始化分組的剖面屬性值與資訊。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| SetPropertyValue(String, Object) |
設定群組剖面屬性的值。 |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |